Announcement Announcement Module
Collapse
No announcement yet.
HibernateTemplate & Transaction Participation Question Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • HibernateTemplate & Transaction Participation Question

    Hi all,

    I read the Spring 1.2.4 reference (PDF) and in page 125 it says :

    ...
    HibernateTemplate will ensure that sessions are properly opened and closed, and
    automatically participate in transactions
    ...
    What does it mean by 'automatically participate in transactions' ?

    Are the following statements true regarding the above phrase ?

    a. When my apps use HibernateTemplate I don't need the following statement :
    Code:
    ...
    Transaction trans = session.beginTransactions();
    
    try
    {
       ...
       trans.commit();
    {
    catch (Exception e)
    {
      ...
      trans.rollback();
    }
    ...
    b. When my apps use HibernateTemplate I don't need the following declaration :
    Code:
    ...
    <bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
       <property name="sessionFactory" ref="sessionFactory"/>
    </bean>
    
    <bean name="classUnderTransaction" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
       <property name="transactionManager" ref="txManager"/>
       <property name="target" ref="classUnderTransactionTarget"/>
       ...
    </bean>
    
    ...
    c. What if I run my applications on EJB environment, do I still need the above code & transaction declaration even if I already use HibernateTemplate ?

    Any clarifications would be greatly appreciated.

    Regards,


    Setya

  • #2
    HibernateTemplate &amp; Transaction Participation Question

    Somebody please give me some explanations,

    Regards,

    Setya

    Comment


    • #3
      automatically participate in transactions
      If you are using Spring transaction managers (Local or JTA), then HB template will be aware of any transactions that are started or managed by these.
      Besides the reference documentation I recommend the books from the site which explain at length the details of the Spring infrastructure, AOP and transaction management.

      Comment


      • #4
        Thanks for the explanation,

        Originally posted by costin
        If you are using Spring transaction managers (Local or JTA), then HB template will be aware of any transactions that are started or managed by these.
        When my apps run under HibernateTemplate and I want to get involved in transaction management, do I still need to define the declarative transaction management ? or explicitly call transaction's commit/rollback ?

        Besides the reference documentation I recommend the books from the site which explain at length the details of the Spring infrastructure, AOP and transaction management.
        Which books ?


        Regards,

        Setya

        Comment


        • #5
          When my apps run under HibernateTemplate and I want to get involved in transaction management, do I still need to define the declarative transaction management ? or explicitly call transaction's commit/rollback ?
          See the reference documentation (chapter 8) - you can use Spring declarative or/and programative approaches (which includes commit/rollback).
          However, if you really want to you can create transactions directly on the HB sessions however you'll basically loose a lot of the benefits provided by Spring.

          Which books ?
          http://www.springframework.org/bookreview

          You can reads about each of them to make an opinion of which one is most suited in your case. Also be sure to check the spring official samples and the spring site/wiki which contain a lot of links to tutorial or related sites (like springhub.com).

          Comment

          Working...
          X