Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

spring transaction management only

 
manish ahuja
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
 
David Newton
Author
Rancher
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.
 
Jayaraj Jaganathan
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




 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic