Results 1 to 8 of 8

Thread: HibernateTransactionManager rollback won't work

Threaded View

  1. #1
    Join Date
    Jun 2007
    Posts
    14

    Default Mixing JDBC and Hibernate Access (old:HibernateTransactionManager rollback won't work

    I'm facing a serious problem when dealing with the HibernateTransactionManager rollback method.
    (I have to reimplement a jdbc layer with hibernate, while the api of the layer has to remain the same. Therefore I have to substitute a method wich uses the jdbc connection rollback method under the hood with a method that now uses the HibernateTransactionManager rollback method.)
    I use the transactionManager the following way:

    Code:
    DefaultTransactionDefinition def = new DefaultTransactionDefinition();
    def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
    TransactionStatus status = transactionManager.getTransaction(def);
    transactionManager.rollback(status);
    I know that my transactionManager is configured properly and rollback works. This is because i implemented some tests with AbstractTransactionalDataSourceSpringContextTests. After every test everything is rolled back properly. Also calling

    Code:
    this.transactionManager.rollback(this.transactionStatus);
    in a Testcase works fine.

    But when doing it in another bean (with properly injected transactionManager) a rollback won't work. I've played with several PropagationBehaviors and combinations on where in the code I set them.

    I also took the AbstractTransactionalDataSourceSpringContextTests source code and designed my class like this (especially the behavior of TransactionDefinition and TransactionStatus).

    When debugging the code I discovered that "my variant" behaves very similiar to the one of the AbstractTransactionalDataSourceSpringContextTests class.
    In the Method "private void processRollback(DefaultTransactionStatus status)" of AbstractPlatformTransactionManager my variant does either a "doRollback(status);" or a"doSetRollbackOnly(status);" while the AbstractTransactionalDataSourceSpringContextTests rollback always does "doRollback(status);". This propagates forword to a "jdbcContext.connection().rollback();" and so on...

    So to me, everything looks fine, but the results aren't...

    Can anybody help with some hints on this?

    Thanks in advance

    ps: I have to stick to this pattern, so declarative or programmatic transaction demarcation is out of the way.

    pps: i also tried the simple

    Code:
    Connection conn = DataSourceUtils.getConnection(dataSource);
    conn.rollback();
    or the more sophisticated?

    Code:
    TransactionAwareDataSourceProxy proxy = new TransactionAwareDataSourceProxy(dataSource); 
    proxy.getConnection().rollback();
    approach... but they won't work. The only rollback that worked so far was with AbstractTransactionalDataSourceSpringContextTests (same datasource, same transactionManager).

    ppps:
    spring 2.0.6
    hibernate 3.2.4.sp1
    hsql database (i also tried db2, but same result)
    Last edited by callisto; Jun 25th, 2007 at 01:46 PM. Reason: changed title

Posting Permissions

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