-->
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.  [ 1 post ] 
Author Message
 Post subject: persisting entity causes object graph traversal
PostPosted: Wed Jul 23, 2008 5:50 pm 
Newbie

Joined: Tue Feb 20, 2007 12:01 pm
Posts: 6
Hello,

We are using hibernate 3.X thru JPA.

So I have an entity and it has many relationships thru collections to many other entities. Our code generator marked all these collections with "CascadeType.All" and "fetch=FetchType.LAZY".

When we persist entity A by calling EntityManager.Persist(), i see that Hibernate is hitting the DB to load the collections on the A - many many select statements. These collections are lazy, but they are all getting loaded at the time of the persist! Then when it pulls in those collections, it goes on and pulls in the collections on those associated entities! Pretty soon our whole DB is in memory :)

Reading up on CascadeType.All, I would think that it would cause the entities in the annotated collection to be persisted when the A is persisted, fine. By why would it try to load up the collection by hitting the DB with a select statement? Shouldn't the graph traversal stop when it hits an uninstantiated lazy-load collection?

Also, if we have an entity A that has a collection of entity B's, is CascadeType.All/CascadeType.Persist the only way to say "when you persist the A, persist the transient B's too"? Or can we expect hibernate to traverse the graph of objects (at least the instantiated ones), looking for associated entities to persist?

Thanks,

JP


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

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.