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?