-->
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: Hibernate session management....
PostPosted: Fri Feb 18, 2011 5:08 pm 
Newbie

Joined: Sun Jul 23, 2006 3:08 pm
Posts: 4
My sample dao: In one single transaction, we will have to execute few methods as shown below which would involve create,update,delete, so we cannot
commit in the code. Hence, we rely on Spring Transaction Manager which we configured and it is working as expected.


public class TestDao extends HibernateDaoSupport
public Collection searchForItems() {
try {
Session session = this.getSession();
Criteria criteria = session.createCriteria();
Collection collection= criteria.list();
return collection;
} catch (HibernateException e) {

}
}
}

Transaction:
The transaction will be taken care of by Spring Transaction Manager configured and this is working fine.

Questions:1. My First Question is, in the above code should we close the session explicitly (like session.close()) or when the Spring Transaction Manager commits the unit of
work, it will take care of closing sessions.
2. My Second Question is, if we should close the session (like session.close()) will this trigger a commit meaning will the unit of work to that point will get commited.

Sessionfactory configuration:
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dsJndi"></property>
<property name="configLocations">
<list>
<value>/WEB-INF/hibernate-config.xml</value>
</list>
</property>
</bean>


Top
 Profile  
 
 Post subject: Re: Hibernate session management....
PostPosted: Sun Feb 20, 2011 8:23 am 
Newbie

Joined: Sun Feb 20, 2011 7:08 am
Posts: 7
1. Spring will take care of it.
2. Closing it will trigger a commit, otherwise it will commit when the transaction ends.


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.