Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

spring transaction management only

Ranch Hand
Posts: 312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can always use the AOP support to wrap methods in transactions.
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.


Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic