This week's book giveaway is in the Beginning Java forum.
We're giving away four copies of Learn Java with Math: Using Fun Projects and Games and have Ron Dai on-line!
See this thread for details.
Win a copy of Learn Java with Math: Using Fun Projects and Games this week in the Beginning Java 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 ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Junilu Lacar
  • Martin Vashko
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Scott Selikoff
  • salvin francis
  • Piet Souris

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.

Thanks,
Sushant
 
Author
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
hai,

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.

-Manish




 
Aaaaaand ... we're on the march. Stylin. Get with it tiny ad.
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!