Results 1 to 5 of 5

Thread: HibernateTemplate & Transaction Participation Question

  1. #1

    Default 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. #2

    Default HibernateTemplate & Transaction Participation Question

    Somebody please give me some explanations,

    Regards,

    Setya

  3. #3
    Join Date
    Jan 2005
    Location
    Bucharest, Romania
    Posts
    5,403

    Default

    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.
    Costin Leau
    SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/costinl
    Please use [ c o d e ] [ / c o d e ] tags

  4. #4

    Default

    Thanks for the explanation,

    Quote 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

  5. #5
    Join Date
    Jan 2005
    Location
    Bucharest, Romania
    Posts
    5,403

    Default

    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).
    Costin Leau
    SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/costinl
    Please use [ c o d e ] [ / c o d e ] tags

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •