Announcement Announcement Module
Collapse
No announcement yet.
Roll back with HibernateDAOSupport class Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Roll back with HibernateDAOSupport class

    Incase of DAO s extended by HibernateDAOSupport classes, I tried transcations to work with annotation based declaration:
    -defined transaction in confg.xml
    eg
    <!-- enable the configuration of transactional behavior based on annotations -->
    <tx:annotation-driven transaction-manager="txManager"/>

    <!-- The PlatformTransactionManager for Hibernate-->
    <bean id="txManager" class="org.springframework.orm.hibernate3.Hibernat eTransactionManager">
    <property name="sessionFactory">
    <ref bean="daoservice.SessionFactory" />
    </property>
    </bean>


    -annotate the method with: @Transactional(propagation=Propagation.REQUIRES_NE W)


    For testing I throwed NullPointerException within DAO method
    Eg :
    String test = null;
    if(test.length() >1){
    log.error("Throwing error");
    }

    Transcation was not rolled back even after exception...
    does hibernateDAOSupport classes support enclosing Transction as stated above.

  • #2
    Can you please post the complete code in service and dao classes.

    Comment


    • #3
      Service Class :

      public class Insert{
      private InsertDAO dao;

      @Transactional(propagation=Propagation.REQUIRES_NE W)
      public Long insertValue(abcVO abc){
      dao.insertValue(abc)
      }
      }


      DAO Class:

      public class InsertDAO extends HibernateDaoSupport{

      @Transactional(propagation=Propagation.REQUIRED)
      public Long insertValue(abcVO abc) {
      try{
      getHibernateTemplate().save(abc);
      String strCheck = null;
      if(strCheck.length() == 0 )
      log.error("Throwing error manually");

      }catch(Exception e){
      }
      }

      Here strCheck.length() will throw a runtime exception so my transaction should be roll backed . But it is not happening.

      Comment

      Working...
      X