-->
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.  [ 2 posts ] 
Author Message
 Post subject: Diff btw and currentsession and oepnsession method
PostPosted: Fri Jun 01, 2007 3:53 am 
Beginner
Beginner

Joined: Sun Nov 19, 2006 6:18 am
Posts: 28
<property name="current_session_context_class">thread</property> is used in assocation with currentSession()
This means that if you have a thread in which you create a Session s1 and you dont close s1 and you create another session s2
and then s2 wud point to s1

here in the following code snippet, value1 and value2 are same

but if s1 is closed then s2 would be different

for eg :

public static void main(String[] a)
{
Session session=HibernateUtil.currentSession();
session.beginTransaction();
Iterator itr=session.createCriteria(SmHostBean.class).list().iterator();
//session.getTransaction().commit(); <!-- session not closed-->
SmHostBean smHostBean=null;
while(itr.hasNext())
{
smHostBean=(SmHostBean)itr.next();
}

System.out.println("session in main thread=="+session); //value1
Session session1=HibernateUtil.currentSession();
System.out.println("session in main thread=="+session1); //value2

}


but if in this example i had used opensession then i would have got different sessions i.e s1 and s2 would b diff when s1 is open
in openSession() session.close has to be done explicitly
in getcurrentsession() session is closed when transaction completes

Is my understanding of the two methods correct.

Kindly help


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 11, 2007 1:55 pm 
Beginner
Beginner

Joined: Sun Nov 19, 2006 6:18 am
Posts: 28
Hi,
I understood the difference by going thru src code and it helped me solve my problem also.

Thanks


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