-->
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.  [ 8 posts ] 
Author Message
 Post subject: open session -> open a connection?
PostPosted: Mon Apr 16, 2007 10:31 am 
Regular
Regular

Joined: Mon Oct 02, 2006 12:03 pm
Posts: 62
Hello forum,

A newbie question. Open a session implies that a connection is openned?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 16, 2007 11:57 am 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
Yes. Or at least retrieved from a pool.

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 17, 2007 12:53 pm 
Senior
Senior

Joined: Sat Sep 10, 2005 3:46 pm
Posts: 178
A connection is NOT opened when a session is opened. The connection will be opened when it is needed. When the connection is closed depends on your connection release mode. So a connection may be opened and closed with each data operation on the session.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 17, 2007 1:41 pm 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
I guess you're right. The thing is I use automatic tx demarcation which immediately issues a transaction "begin" which I think needs a db connection (or maybe it's "lazily" managed, but I don't think so).

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 17, 2007 2:29 pm 
Beginner
Beginner

Joined: Sat Apr 17, 2004 1:11 am
Posts: 36
Unless you pass a connection to it like we do in our application...

benster


Top
 Profile  
 
 Post subject: lazy and session software design
PostPosted: Fri Apr 20, 2007 3:29 pm 
Regular
Regular

Joined: Mon Oct 02, 2006 12:03 pm
Posts: 62
So, what about lazy initialitation. If no session is opened, my program will crash because there isn't any session opened. When I get a customer(for example), I open a session and when I have obtained the customer I close the session. So when I access to customer Contacts (lazy="true", it's required) from my program, the session is closed and Contacts won't be loaded correctly, my program will crash!!!

How do you design your software?
How do you take care about this situation?

Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 20, 2007 6:27 pm 
Newbie

Joined: Mon Apr 02, 2007 12:31 pm
Posts: 19
jeusdi,

This is a common concern in Hibernate. The documentation, http://www.hibernate.org/hib_docs/nhibernate/html/collections.html#collections-lazy , lists the basic ways of dealing with this.

Basically, you can either force NHibernate to load all the data before closing the session, or open a new session to load the data. If you open a new session, you need to attach the customer object to the new session using ISession.Lock() or ISession.Update(). Which of these methods you use will depend on your application and data.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 23, 2007 1:18 am 
Regular
Regular

Joined: Wed Oct 25, 2006 10:51 pm
Posts: 71
The rewarded answer was "Yes. Or at least retrieved from a pool." looks to be technically wrong. I don't know if the point he received for answering should be deducted or not ;-)


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