• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Spring Transactions with hibernate

 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am a spring and hibernate learner now. Trying to understand the concept of transactions.
I am using hibernate template in my DAO classes and using annotation to declare the transactions. So far everything is good.

I have a GateWayService and AccountDAO , both are annotated with @Transactional. I am using AccountDAO in the GateWayService as shown below.

And here is AccountDAO.java



Now the problem is, even if I change the propagation level in the @Transaction annotation to any values (like ..supports/required/notsupported ), I am not seeing any change or exceptions . My programe is working fine.

If there is already one transaction initiated in the GateWayService class, and if I am calling AccountDAO which is also having a Transaction, Iam expecting that I should get some different behavior when i change the propagation levels. Is that true ???

Or, the underlying hibernate template always creating one session and hibernate transaction manager creating/using the same transactions in the current thread ?

Can some one help me to understand this.

And in the hibernate configuration i have the current session context as "thread"
<prop key="hibernate.current_session_context_class">thread</prop>

Thanks
Prashanth
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK two things I highly recommend.

1) Stop using HibernateTemplate. In the current versions of Spring and Hibernate you are gaining absolutely no value, just adding a level of unnecessary indirection.
2) Only set transaction stuff at the Service layer, not in the Respository/DAO layer. The Transaction at the Service level is automatically wrapping all your calls to your Repository/DAO layer

Mark
 
Reddy Prashanth
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mark,

Thank you for the update.
So what is the preferred way of using hibernate in spring. Is using the sessionfactory and session directly in my DAO better way ?

Actually I am trying to test that concept of transaction propagation. Will spring always use the same transaction in the current thread ? then how can I test the propagation levels. I appreciate if you could you provide one scenario.


Thanks,
Prashanth
 
You totally ruined the moon. You're gonna hafta pay for that you know. This tiny ad agrees:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic