I am using an Extended Persistence context, SeamManagedPhaseListener, etc. to collect information through a number of wizard-like steps.
When the user confirms, I perform all of my persistence. In the event of some unforseen database error, I want to rollback the transaction, present the user with an error message and allow them to potentially resolve the error and resubmit.
To do this, I catch all exceptions around the persistence logic and issue a
SessionContext.setRollbackOnly();
Something like
try
{
em.persist(x);
} catch (RuntimeEception e)
{
ctx.setRollbackOnly();
//set error message
return "errorpage";
}
Caused by: javax.transaction.NotSupportedException: Transaction already active, cannot nest transactions. at org.jboss.tm.TxManager.begin(TxManager.java:208)