I've fetched the latest hibernate code from jboss' CVS and have deployed it in JBoss 3.2.x. If this is a really bad idea, please let me know.
The problem though, is that if my EJB inserts an object into the database using session.save(object) the object is not actually stored in the database yet.
The object isn't stored in the database until TransactionSynch.beforeCompletion() is called:
Code:
try
{
log.trace("Flushing Session");
session.flush();
}
catch(Throwable t)
{
log.warn("Error flushing session");
}
Now, if anything goes wrong, like if there is already an object with that primary key in the database, the duplicate key exception is lost in the catch, and the EJB method caller will never know that something wrong happened!
Is this really what is intended? Or am I using this wrong?
Do I need to flush() the session manually at the end of each of my EJB methods, or will rethrowing the exception in beforeCompletion() be a better approach?
Eivind