Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Circular relationships in Hibernate not working

 
Adam Kreiss
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Adam Kreiss
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic