-->
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: Simple (novice) question about sessions
PostPosted: Wed Nov 30, 2005 4:41 pm 
Newbie

Joined: Wed Nov 30, 2005 4:24 pm
Posts: 1
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3

Name and version of the database you are using: MySQL


Here's a simple question.

(1) Suppone we have a 'one to many' relationship:
class A has a set of class B, and class B has one reference to class A.

(2) We start a session, and we do a query "from A". It returns a
list of 'A' objects, right?

(3) So we get an 'A' object from the returned list and we can do a.getProperty1(), a.getProperty2(), and even a.getB().getProertyB1()...

Everything is right at this point.

But if we close the session after (2) and before (3), we can still do a.getProperty1(), a.getProperty2(), but we can't do a.getB().getPropertyB1() because B is still part of the closed session!
The exception thrown is: could not initialize proxy - the owning Session was closed

How can I get a.getB().getPropertyB1() after I close the session? And please, don't tell me to leave the session opened because I can't do that in my particular case.

Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 30, 2005 4:51 pm 
Beginner
Beginner

Joined: Tue Apr 05, 2005 4:27 pm
Posts: 40
Location: canada
well, you could either call Hibernate.initialize(a.getB()) to initialize the collection before the session is closed, or you could change the mapping of the collection to lazy=false.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 30, 2005 4:57 pm 
Regular
Regular

Joined: Tue Oct 28, 2003 8:25 am
Posts: 72
Location: Belgium
Or you could reattach the A object to a new session either via Session.lock(theA, LockMode.NONE) or via Session.update(theA).


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.