middletier and Data access layer both have interfaces as @Transactional with all default attributes.
middletier and Data access layer both have interfaces as @Transactional with all default attributes.
Only your service layer should have @Transactional, try removing it from the persistence layer. If my guess is right you probably will now get exceptions that there is no ongoing transaction (due to the @Transactional on the service layer being ignored).
Marten Deinum
Java Consultant / Pragmatist / Open Source Enthousiast / Author
Pro Spring MVC: With Web Flow
Conspect
Have you read the reference guide.
Use the [ code ] tags, young padawan
Ok, As you said i removed @Transactional from data access layer.
I ran my test case but still the same issue. I did not get the exception- no ongoing transaction.
I guess since data access layer is accessed from middle tier and i invoke midlde tier first which basically starts the transaction. The issue still being i could see data inserted into db even after I throw RuntimeException in middletier as the last step.![]()
There really must be something wrong with either your whole setup or your testcase. There can only be data in the database if there is a commit, a commit is generated after a method with @Transactional has ended (depending on the configuration). Even if you call flush you can still rollback those changes a flush isn't a commit.
Can you strip down a working (well non-working) zip it and put it here (or if you like I can pm you my email).
Marten Deinum
Java Consultant / Pragmatist / Open Source Enthousiast / Author
Pro Spring MVC: With Web Flow
Conspect
Have you read the reference guide.
Use the [ code ] tags, young padawan
Has anyone encountered a similar issue? Changes are not rollbacked after flush is called.
Method is transactional, transaction boundary is defined using AOP transaction advice.
In my case flush executes 3 DML statements (1 insert, 2 updates), last update fails due exception from DB trigger. Tried to catch exception and clear & close session, that didn't helped.
Code:if (true) { //throw new BatchJobException("Testing rollback"); -- this works and all changes are rollbacked try { sessionFactory.getCurrentSession().flush(); } catch (Exception e) { sessionFactory.getCurrentSession().clear(); sessionFactory.getCurrentSession().close(); throw new BatchJobException("Testing rollback"); -- changes are not rollbacked } }
Last edited by maris; Jun 18th, 2013 at 10:01 AM.