IntelliJ Java IDE
The moose likes Object Relational Mapping and the fly likes Circular relationships in Hibernate not working Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Object Relational Mapping
Reply Bookmark "Circular relationships in Hibernate not working" Watch "Circular relationships in Hibernate not working" New topic
Author

Circular relationships in Hibernate not working

Adam Kreiss
Ranch Hand

Joined: Sep 12, 2005
Posts: 35
Hey everyone,

I'm not sure if I have something configured wrong or this is the correct behavior for Hibernate (I doubt it) but here it goes.

I have a table of employees. Each employee can be affiliated with another employee through an extra table containing information about how they are related.

So I have an Employee mapping with a <set...> of Relations. Each Relation has another Employee (different than the first) related to it in a <many-to-one...> relationship.

When I traverse this path, I can get the base Employee, from there I can get the relationship, from there I can get the second Employee but when I try to access any related data for that employee, it all comes back null. So it feels like it looses all the mappings to other tables the second time around.

Does anyone know if there is some property I need to set to get this to allow me to continue to traverse the data?

Thanks
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 16622

Yes, the exact name I do not remember. But in your mapping you can state how far down you want to go. How many levels? So in the circular reference you can say set it to go 5 levels deep. I think you are seeing the default depth. I think "depth" is part of the name, but don't remember the tag name.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Adam Kreiss
Ranch Hand

Joined: Sep 12, 2005
Posts: 35
There is a property, hibernate.max_fetch_depth that you can declare in the XML config file. This doesn't seem to do the trick though. I've set it to 10 which should be more than enough and enabled outer-joins through the entire path of objects I need to traverse and it still comes back as null when I try to get a collection out of the second Employee.

Any other ideas? Or is there something I'm missing on this?

Thanks
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 16622

OK, what about this question. When are you getting the related objects, are you still in a Unit of Work?

What about the fetching strategies, is it set in the query, or do you have the mapping set to eager fetch.

But also thinking about it, how would Hibernate write a query that would return N number of depth? Not sure that you can even with just SQL.

Mark
 
 
subject: Circular relationships in Hibernate not working
 
Threads others viewed
How do we update relationship data using CMP model entity bean ??
simple example implementation?
EJB and CMR questions
So much on the Left Joins in Hibernate
Hibernate Caching not clear
WebSphere development made easy
without the weight of IBM tools
http://www.myeclipseide.com