These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Infinite loop with StatelessSession and recursive relations
PostPosted: Wed Jul 18, 2007 10:09 am 
Newbie

Joined: Wed Apr 28, 2004 6:44 am
Posts: 15
Location: Amsterdam, Netherlands
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


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 18, 2007 11:02 am 
Newbie

Joined: Wed Apr 28, 2004 6:44 am
Posts: 15
Location: Amsterdam, Netherlands
I've realized that setting 'lazy="false"' on the level of the class-mapping causes the problem, because it overrides all lazy-declarations on the level of associations and properties.

Therefore, mapping the class with lazy="true" fixes the problem, for the particular bit of code at least.

I have a need in other code to use a StatelessSession where I do need to traverse some of the relations; explicitly mapping those relations as lazy="false" prevents breakage there.


For the moment, problem therefore seems solved.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.