Gavin? If you got a minute could you tell me if my assumptions in my two posts from Dec 1 are correct? I'd be happy to have some more knowledge about that stuff ;).
Thx
Sorry, which posts?
@Gavin: This thread, page three, two posts by bfo81 on Dec 1st :).
"bfo81" wrote:
But I must confess, I am not 100% sure at which point in time a transaction starts and ends. My imagination is like this:
- before methode starts: em.getTransaction().start().
- after method ends: em.getTransaction().commit() (or rollback() if setRollbackOnly() was called or a RuntimeException occured).
- and whenever there are Java transactions running, a database transaction is started before the first db access (e.g. set autocommit=0 in MySQL or begin tran in MS SQL). And after writing was finished, a database commit (or rollback) is called.
GAVIN? Could you take as on a ride into the deep misterys of the Java Transaction API and its interactions with the EntityManager here? Only a short comment wether my findings are correct :)
"bfo81" wrote:
- If a rollback was set (setRollbackOnly() or RuntimeException) there won't be any SQL statements sent to the database at the end of a method. If you called em.flush() before, then statements were already created and only then you need a database rollback, right?
"bfo81" wrote:
- Ist there a SQL commit called at the end of em.flush()? If yes, and if there are e.g. constraints violated, the database rolls back the changed stuff automatically and throws an exception, right?
"bfo81" wrote:
- How does the EntityManager know which entities changed? Does he hold a copy of every managed entity in memory and compare it to the actual entities, field by field?!? Or are there some interceptors doing some observer stuff on the entity?