I am new to Spring.
The following link talks about implementing Spring declarative transaction management around an application's Hibernate based DAOs which are based on plain Hibernate3 API; Thus avoiding usage of Spring API in an application's DAO
java classes.
http://static.springframework.org/spring/docs/2.0.x/reference/orm.html#orm-hibernate-straight Based on the above link, I setup my config file and a DAO java class whose CRUD methods in turn call the appropriate methods on the Session object. But none of the crud operations are being Commited into the database.
Below is the code snippet:
A part of my xml config file:
<bean id="hbManager" class="org.springframework.orm.hibernate3.Hibernat eTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<bean id="myCustomDAO" class="x.y.LocalDAO">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<aop:config>
<aop ointcut id="xMethods" expression="execution(* x.y.LocalDAO.*(..))"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="xMethods"/>
</aop:config>
<tx:advice id="txAdvice" transaction-manager="hbManager">
<tx:attributes>
<tx:method name="create" propagation="REQUIRED"/>
<tx:method name="update" propagation="REQUIRED"/>
<tx:method name="delete" propagation="REQUIRED"/>
<tx:method name="get" propagation="REQUIRED" read-only="true"/>
</tx:attributes>
</tx:advice>
*************************
In my localDao class, I get the Session from the Sessionfactory and close after each database all as follows:
Session session = sessionFactory.openSession();
//some database call
session.close();
Question: Do I need to do as above in the DAO class?
If not, is there a way to reuse the Session created by HibernatePersistenceManager (please refer to the config xml code snippet above) in my DAO class in order to call the CRUD methods on that Session object???
Also are any changes needed in the config xml?
Any code snippets are highly helpful.
Thanks in advance for your valuable time and interest.