Is it legitimate to invoke Transaction.begin() after invoking Transaction.commit()?
Tapestry's Hibernate support is designed to automatically commit the transaction under user-control, then start a new transaction for any additional (usually read-only) behavior afterwards:
Code:
public class HibernateSessionManagerImpl implements HibernateSessionManager, ThreadCleanupListener
{
private final Session session;
private Transaction transaction;
public HibernateSessionManagerImpl(HibernateSessionSource source)
{
session = source.create();
transaction = session.beginTransaction();
}
public void commit()
{
transaction.commit();
transaction.begin();
}
But I've gotten user feedback that this isn't working correctly because a second Transaction is being created.
I'm thinking I should change my code inside commit() to be
Code:
transaction.commit();
transaction = session.beginTransaction();
My question is, why is it possible (and not an IllegalStateException, for instance) to call begin() on a Transaction more than once?