Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Object Relational Mapping
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Ron McLeod
Tim Cooke
Paul Clapham
Liutauras Vilda
Sheriffs:
Junilu Lacar
Rob Spoor
Jeanne Boyarsky
Saloon Keepers:
Stephan van Hulst
Carey Brown
Tim Holloway
Piet Souris
Bartenders:
Forum:
Object Relational Mapping
HIbernate Mapping problem
Gil Carvalho
Ranch Hand
Posts: 80
posted 9 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hello
Can someone help me with this.
I have a table Users and another one roles (mapped) - one role can be done by several users
Thsi is my Users Entity
@Entity @Table(name = "USERS") public class Users implements Serializable { private static final long serialVersionUID = 1L; @Column(name = "USER_ID", nullable = false) @Basic(fetch = FetchType.EAGER) @Id @GeneratedValue(strategy = GenerationType.AUTO) @XmlElement Integer userId; @Column(name = "USERNAME", length = 45, nullable = false) @Basic(fetch = FetchType.EAGER) @XmlElement String username; @Column(name = "PASSWORD", length = 45, nullable = false) @Basic(fetch = FetchType.EAGER) @XmlElement String password; @Column(name = "ENABLED", nullable = false) @Basic(fetch = FetchType.EAGER) @XmlElement Boolean enabled; @ManyToOne(fetch = FetchType.LAZY) @JoinColumns({ @JoinColumn(name = "ROLES_ID", referencedColumnName = "USER_ROLE_ID")}) @XmlTransient UserRoles userRoles; public void setUserId(Integer userId) { this.userId = userId; } public Integer getUserId() { return this.userId; } public void setUsername(String username) { this.username = username; } public String getUsername() { return this.username; } public void setPassword(String password) { this.password = password; } public String getPassword() { return this.password; } public void setEnabled(Boolean enabled) { this.enabled = enabled; } public Boolean getEnabled() { return this.enabled; } public void setUserRoles(UserRoles userRoles) { this.userRoles = userRoles; } public UserRoles getUserRoles() { return userRoles; } public Users() { } public void copy(Users that) { setUserId(that.getUserId()); setUsername(that.getUsername()); setPassword(that.getPassword()); setEnabled(that.getEnabled()); setUserRoles(that.getUserRoles()); } }
An my Roles entity
@Entity @Table(name = "USER_ROLES") @XmlAccessorType(XmlAccessType.FIELD) public class UserRoles implements Serializable { private static final long serialVersionUID = 1L; @Column(name = "USER_ROLE_ID", nullable = false) @Basic(fetch = FetchType.EAGER) @Id @GeneratedValue(strategy = GenerationType.SEQUENCE) @XmlElement Integer userRoleId; @Column(name = "AUTHORITY", length = 45, nullable = false) @Basic(fetch = FetchType.EAGER) @XmlElement String authority; @OneToMany(mappedBy = "userRoles", cascade = { CascadeType.PERSIST }, fetch = FetchType.LAZY) @XmlElement(name = "", namespace = "") java.util.Set<gmc.gestaxi.modelo.Users> userses; public void setUserRoleId(Integer userRoleId) { this.userRoleId = userRoleId; } public Integer getUserRoleId() { return this.userRoleId; } public void setAuthority(String authority) { this.authority = authority; } public String getAuthority() { return this.authority; } public void setUserses(Set<Users> userses) { this.userses = userses; } public Set<Users> getUserses() { if (userses == null) { userses = new java.util.LinkedHashSet<gmc.gestaxi.modelo.Users>(); } return userses; } public UserRoles() { } }
When i use spring hibernate i want to define user details with roles (1 or 2) but i receive a null field in my users table
userId=
[null]
username=[man] password=[123] enabled=[true]
What's wrong please??
Thanks
And will you succeed? Yes you will indeed! (98 and 3/4 % guaranteed) - Seuss. tiny ad:
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
https://www.kickstarter.com/projects/paulwheaton/low-tech
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Which Annotation should be used for @Embedded class when used as primary key ?
Simple JPA Entity with NUMBER
how to update OneToMany
JPA Provider issue
Mapping Objects
More...