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
Help coderanch get a
new server
by contributing to the
fundraiser
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
Paul Clapham
Devaka Cooray
Liutauras Vilda
Sheriffs:
Jeanne Boyarsky
paul wheaton
Henry Wong
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Tim Moores
Carey Brown
Mikalai Zaikin
Bartenders:
Lou Hamers
Piet Souris
Frits Walraven
Forum:
Object Relational Mapping
One to many mapping problem
Predrag Ristic
Greenhorn
Posts: 28
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I have one to many mapping between Role and RoleFunctions but getRoleFunctions() method doesn't return anything.Can anyone tell me why?Here are the classes:
Role.java
package com.spinnaker.pedja; import java.io.Serializable; import java.util.ArrayList; import java.util.Collection; import javax.persistence.*; import static javax.persistence.FetchType.EAGER; @Entity @Table(name = "role", schema = "edukacija") public class Role implements Serializable { @Id @Column(name = "roleId") private int roleId; @Column(name = "role_name") private String roleName; public String getRoleName() { return roleName; } public void setRoleName(String roleName) { this.roleName = roleName; } @OneToMany(mappedBy = "role", fetch = EAGER, targetEntity = RoleFunctions.class) private Collection<RoleFunctions> roleFunctions = new ArrayList<RoleFunctions>(); public int getRoleId() { return roleId; } public void setRoleId(int roleId) { this.roleId = roleId; } public Collection<RoleFunctions> getRoleFunctions() { return roleFunctions; } public void setRoleFunctions(Collection<RoleFunctions> roleFunctions) { this.roleFunctions = roleFunctions; } }
RoleFunctions.java
package com.spinnaker.pedja; import java.io.Serializable; import javax.persistence.*; import static javax.persistence.FetchType.EAGER; @Entity @Table(name = "role_functions") public class RoleFunctions implements Serializable { @EmbeddedId private RoleFunctionsPk roleFunctionsPk; // @Column(name = "role_id", insertable = false, updatable = false) // private int roleId; @ManyToOne(fetch=EAGER) @JoinColumn(name="roleId", insertable = false, updatable = false) private Role role; public RoleFunctionsPk getRoleFunctionsPk() { return roleFunctionsPk; } public void setRoleFunctionsPk(RoleFunctionsPk roleFunctionsPk) { this.roleFunctionsPk = roleFunctionsPk; } // public int getRoleId() { // return roleId; // } // // public void setRoleId(int roleId) { // this.roleId = roleId; // } public Role getRole() { return role; } public void setRole(Role role) { this.role = role; } }
RoleFunctonsPk.java
package com.spinnaker.pedja; import java.io.*; import javax.persistence.*; @Embeddable public class RoleFunctionsPk implements Serializable { /** * */ private static final long serialVersionUID = -4381904450375257793L; @Column(name = "roleId", insertable = false, updatable = false) private int roleId; @Column(name = "role_function", insertable = false, updatable = false) private String roleFunction; public int getRoleId() { return roleId; } public void setRoleId(int roleId) { this.roleId = roleId; } public String getRoleFunction() { return roleFunction; } public void setRoleFunction(String roleFunction) { this.roleFunction = roleFunction; } @Override public boolean equals(Object o) { if (o == this) { return true; } if (!(o instanceof RoleFunctionsPk)) { return false; } RoleFunctionsPk other = (RoleFunctionsPk) o; return (this.roleId == other.roleId && this.roleFunction .equals(other.roleFunction)); } @Override public int hashCode() { final int prime = 31; int hash = 17; hash = hash * prime + this.roleId; hash = hash * prime + this.roleId; return hash; } }
Cameron Wallace McKenzie
author and cow tipper
Posts: 5009
1
I like...
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Is it returning null, or is it returning an empty list, or is it throwing an exception? Are there actually associated objects in the database?
With a little knowledge, a
cast iron skillet
is non-stick and lasts a lifetime.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
issue with Xdocler Ant Task
Hibernate association mapping
Cannot be cast to java.io.Serializable
using Hibernate with Session Bean
Can't use Optimistic Locking
More...