-->
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: when session should be closed?
PostPosted: Fri Mar 16, 2007 8:13 am 
Beginner
Beginner

Joined: Wed Mar 14, 2007 10:19 am
Posts: 24
I have an application, and in the DAO layer where the database transactions occur I have the following sample code:

Code:
public User getUser() {

Session session = HibernateUtil.getCurrentSession();
Transaction tx = session.beginTransaction();
......

tx.close();
session.close();

}



1)I want to ask if I must close session in every DAO method as I am doing above?Or I should never close it?
2)Is session.flush() necessary;
3)When I get session --> HibernateUtil.getCurrentSession();
if there is existing session, Hibernate will not create a new one right?If there is no session, Hibernate will create a new one?

Thanking you in advance...


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 16, 2007 9:04 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
http://hibernate.org/42.html

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 16, 2007 9:21 am 
Beginner
Beginner

Joined: Wed Mar 14, 2007 10:19 am
Posts: 24
christian wrote:
http://hibernate.org/42.html


Yes I have already read documentations and the above are some basic questions that I have after this reading.

thanks


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.