-->
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.  [ 3 posts ] 
Author Message
 Post subject: Lazy initialization of collection members, Spring&Hibern
PostPosted: Wed Mar 16, 2005 7:56 pm 
Newbie

Joined: Thu Mar 04, 2004 9:10 pm
Posts: 6
Here's the issue: I'm loading stuff via Springified Hibernate beans (so I'm not controlling the session directly).

In my view, I'm loading up an entity that has a one-to-many, and looping through that collection, say:

#foreach ($child in $parent.children)
$child.name
#end

This fails here, because each child is not initialized, and I get an error saying

" the owning Session was closed (could not initialize proxy - the owning Session was closed) - org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed"

which does make some sort of sense.

my question is, what strategy can I use to enforce the reloading of these things, or should I manually load them in my action and not try to go through 3 levels of relational abstraction outside of the context of a Session?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 17, 2005 3:38 am 
Senior
Senior

Joined: Sun Mar 14, 2004 10:16 am
Posts: 129
Location: Ankara
if you are not controlling the session and if it can be closed somehow,
you must use lazy="false", no other solutions.

_________________
-developer


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 17, 2005 8:20 am 
Newbie

Joined: Wed Mar 09, 2005 5:03 am
Posts: 7
You can always use transactions in order to have an ability to use lazy initializations (spring-reference:7.3.2):
Code:
DefaultTransactionDefinition def = new DefaultTransactionDefinition()
def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
TransactionStatus status = transactionManager.getTransaction(def);
try {
// execute your business logic here:
// bean method execution
} catch (MyException ex) {
transactionManager.rollback(status);
throw ex;
}
transactionManager.commit(status);


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.