jQuery in Action, 3rd edition
The moose likes Spring and the fly likes spring transaction management only Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "spring transaction management only" Watch "spring transaction management only" New topic

spring transaction management only

manish ahuja
Ranch Hand

Joined: Oct 23, 2003
Posts: 312
Hi All,

I am currently using Hibernate solution for my project. This is a standalone service bundled as a library jar file.
We have some transaction handling and currently we are using code level transaction management like HibernateUtil.beginTransaction() , HibernateUtil.commitTransaction() and HibernateUtil.closeSession().

I want to replace only the transaction handling component using Spring. The examples I see on the web entails usage of SpringHibernate support or Spring's implementation for Hibernate. We don't want to disturb our current Hibernate implementation but instead use the existing Hibernate solution reference i.e. just have the Spring transaction handler and make it use the already in place hibernate config for all session management reference rather than reinitializing everything again in Spring configurations.

Let me know your thoughts on this.

David Newton

Joined: Sep 29, 2008
Posts: 12617

You can always use the AOP support to wrap methods in transactions.
Jayaraj Jaganathan
Ranch Hand

Joined: Jun 29, 2009
Posts: 70

i have asked this question to myself some time back and found some information.

1. creating data source
2. you have to use spring hibernate session factory.
3. you have to inject spring hibernate session factory to your dao.
4. transaction management can be done by spring aop
5. you have to get session factory in which spring has enabled the transaction management. by righting the code as below

refer sample config

manish ahuja
Ranch Hand

Joined: Oct 23, 2003
Posts: 312
Thanks Jayaraj.

One more question here. Is there a need to repeat configurations for datasource, sesssion factory and hibernate in the spring config xml file.
Since these are already declared in the hibernate.cfg.xml file is there anyway I can refer the hibernate config file for the above mentioned configurations or is it necessary to have the same in Spring.

In the sample you highlighted below the transaction interceptor comes into play during all DAO execution. The approach I am following is controlling transactions at one level above DAO (i.e. a Manager or Service layer) and not doing any transaction related activities within the DAO. So for my case I will just have to replace <value>*DAO</value> with something like <value>*Manager</value>

Let me know your thoughts.


I agree. Here's the link: http://aspose.com/file-tools
subject: spring transaction management only
It's not a secret anymore!