To rollback when have error, I use javax.ejb.SessionContext to do that,
first I mark a point to rollback by sessionContext.getUserTransaction().begin()
Then I use sessionContext.getUserTransaction().rollback()
to rollback and use sessionContext.getUserTransaction().commit();
to should complete transaction before returning.
but the problem is if there is nothing changed, this will throws org.hibernate.exception.GenericJDBCException: could not prepare statement
.
Conclusion: There is anyway to stop SessionContext ?