Hi,
I'm using a StatelessSession to read all records in some tables. Now the entity in one of those tables happen to have a recursive relation: A Card can be replaced by another Card. In that case, there's a link from the new Card to the old Card, and from the old Card to the new Card. These links are mapped as uni-directional many-to-one associations. (Thinking about it, they could actually be mapped as a one-to-one association; I don't know if it will make a difference but I'll try that avenue next).
So let's assume that there are 2 cards, Card 1 and Card2, and Card1 is the old card and Card2 the new card.
When the scrolling through this table, once Hibernate hits upon a row involved in such a recursive relation, Hibernate loads first Card 1, then Card 2, then Card 1, then Card 2, etc, until there's a heapdump.
Of course, a StatelessSession does not utilize a session-cache. Therefore, there is no history of what's loaded, and what's not.
I wish however, that there was a way to stop Hibernate from eagerly loading those relations! I actually don't even need the related instances anyways, so I don't care if it doesn't load them at all, and throws an exception when trying to access the related instance.
The entity itself is mapped with lazy="false"; I tried adding an explicit lazy="proxy" to the many-to-one association mappings but no difference.
I can post parts of the mapping, code and logfiles if required but I hope the explanation of the problem is clear enough as it is.
Does anyone have a solution to this problem other than breaking the association that causes the recursion?
Cheers,
--Tim
|