I am working with JPA 2 Hibernate implementation and Spring MVC to manage transactions
I am using Generic DAO pattern to manage database operations
Currently, we have a transaction that is a single method, something like:
someDao.save (someObject)
It is a @Transactional
method invoked from a JSF page.
The method save is inherited from Generic DAO, it persists to database many entities with cascade oneToMany relationships, but it has to execute some 1000s of insert statements in the database, so it takes a very long time.
I'd like to offer a way to the user to cancel the operation, but so far, I'm unable to do that, when I call the method save(), it cannot be canceled till all the inserts have been executed.
I tried to throw some exceptions, to rollback transaction from injected PersistenceContext, but it's useless, it just finishes with no error :(
Obviously, I cannot throw an exception from within the method, it's just a single call from my source. JPA PersistenceContext does everything
Is there a way to cancel the operation and force it to rollback?