Hello,
i'm using Smartgwt EE and have an issue with a JPA Datasource and a unidirectional oneToMany relation.
How can i achieve that i can see corresponding entities? As an example i have a ListGrid with Users and i want to show the Roles that the User has (in the same ListGrid with nested ListGrid, MasterPage or something else).
I have two Java Classes with JPA Annotations and corresponding *.ds.xml.
User.java
User_datasource.ds.xml
Role.java
Role_datasource.ds.xml
regards Pawel
i'm using Smartgwt EE and have an issue with a JPA Datasource and a unidirectional oneToMany relation.
How can i achieve that i can see corresponding entities? As an example i have a ListGrid with Users and i want to show the Roles that the User has (in the same ListGrid with nested ListGrid, MasterPage or something else).
I have two Java Classes with JPA Annotations and corresponding *.ds.xml.
User.java
Code:
package com.c1.perpetuom.domain; import java.io.Serializable; import java.util.Set; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.JoinTable; import javax.persistence.OneToMany; import javax.persistence.Table; @Entity @Table (name="Users") public class User implements Serializable{ @Id @GeneratedValue(strategy = GenerationType.AUTO) @Column(name = "id") private Long id; private Long key; private String name; private String surname; private String login; private String password; @OneToMany @JoinTable(name="user_roles", joinColumns=@JoinColumn(name="UserID", referencedColumnName="ID" ), inverseJoinColumns=@JoinColumn(name="RoleID", referencedColumnName="roleID")) private Set<Role> roles; public Long getKey() { return key; } public void setKey(Long key) { this.key = key; } public String getName() { return this.name; } public void setName(String name) { this.name = name; } public String getSurname() { return this.surname; } public void setSurname(String surname) { this.surname = surname; } public String getLogin() { return this.login; } public void setLogin(String login) { this.login = login; } public String getPassword() { return this.password; } public void setPassword(String password) { this.password = password; } public Set<Role> getRoles() { return roles; } public void setRoles(Set<Role> roles) { this.roles = roles; } public Long getId() { return this.id; } public void setId(Long id) { this.id = id; } }
Code:
<DataSource ID="User_datasource" serverConstructor="com.isomorphic.jpa.JPADataSource" beanClassName="com.c1.perpetuom.domain.User" > <fields> <field primaryKey="true" name="id" type="sequence" hidden="true" /> <field name="key" type="integer" hidden="true" required="false" /> <field name="name" type="text" title="Name" required="false" /> <field name="surname" type="text" title="Surname" required="false" /> <field name="login" type="text" title="Login" required="false" /> <field name="password" type="text" title="Password" required="false" /> <field name="roleID" type="Role_datasource" required="false" foreignKey="Role_datasource.roleID" multiple="true"/> </fields> </DataSource>
Code:
package com.c1.perpetuom.domain; import java.io.Serializable; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.Table; @Entity @Table (name="Roles") public class Role implements Serializable { @Id @GeneratedValue(strategy = GenerationType.AUTO) @Column(name = "roleID") public long getRoleID() { return roleID; } public void setRoleID(long roleID) { this.roleID = roleID; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } private long roleID; private String description; public String toString() { StringBuilder sb = new StringBuilder(); sb.append("RoleID: ").append(getRoleID()).append(", "); sb.append("Description: ").append(getDescription()); return sb.toString(); } }
Code:
<DataSource ID="Role_datasource" serverConstructor="com.isomorphic.jpa.JPADataSource" beanClassName="com.c1.perpetuom.domain.Role" > <fields> <field primaryKey="true" name="roleID" type="sequence" hidden="true" /> <field name="description" title="Description" type="text" required="true" /> </fields> </DataSource>
Comment