aspose file tools*
The moose likes Object Relational Mapping and the fly likes Getting Hibernate bidirectional mapping working with annotations Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Getting Hibernate bidirectional mapping working with annotations" Watch "Getting Hibernate bidirectional mapping working with annotations" New topic
Author

Getting Hibernate bidirectional mapping working with annotations

J Ellis
Greenhorn

Joined: Aug 23, 2009
Posts: 27
Hi all,

I have a very simple database with two tables: Departments [Id, Name] and Employees [Id, DepartmentsId, FirstName, LastName]. I am trying to get a bidirectional relationship working in Hibernate but it keeps generating an infinite loop and then a StackOverFlow exception. Here are my classes:

Departments:



Employees:



My HQL query is simply: "FROM Departments d JOIN FETCH d.employeeses e".

I have tried Departments using both the existing and commented-out sets of annotations on "getEmployeeses". According to everything I have been reading, including the Hibernate documentation on bidirectional collections (http://docs.jboss.org/hibernate/orm/3.6/reference/en-US/html/collections.html#collections-bidirectional) these annotations should, in effect, set the "inverse" types for the two tables and thus avoid the problem I am running into, that every time "Departments" grabs an "Employees" set, each new "Employees" object creates another "Departments," which then creates another "Employees" set, so on and so forth, into an infinite loop. However, the issue still occurs unless I remove the "Departments" object from the "Employees" class, thus creating a unidirectional mapping, which I do not want to do. What the heck am I doing wrong here?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Getting Hibernate bidirectional mapping working with annotations
 
Similar Threads
Unable to understand exception
Hibernate: Why is bag semantic getting applied when I'm not using Lists?
problem with @FieldResult, mapping does not seem to work
Inserting into table with Hibernate question
One to many Relation