Results 1 to 3 of 3

Thread: Roll back with HibernateDAOSupport class

  1. #1
    Join Date
    Aug 2009
    Posts
    5

    Default 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. #2
    Join Date
    Sep 2008
    Posts
    1

    Default

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

  3. #3
    Join Date
    Aug 2009
    Posts
    5

    Default

    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.

Tags for this Thread

Posting Permissions

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