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:
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 callingCode:DefaultTransactionDefinition def = new DefaultTransactionDefinition(); def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); TransactionStatus status = transactionManager.getTransaction(def); transactionManager.rollback(status);
in a Testcase works fine.Code:this.transactionManager.rollback(this.transactionStatus);
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
or the more sophisticated?Code:Connection conn = DataSourceUtils.getConnection(dataSource); conn.rollback();
approach... but they won't work. The only rollback that worked so far was with AbstractTransactionalDataSourceSpringContextTests (same datasource, same transactionManager).Code:TransactionAwareDataSourceProxy proxy = new TransactionAwareDataSourceProxy(dataSource); proxy.getConnection().rollback();
ppps:
spring 2.0.6
hibernate 3.2.4.sp1
hsql database (i also tried db2, but same result)



Reply With Quote