Reputation: 9697
I have a single service method annotated with Propagation.Required
. It performs three separate operations .
Forgive my ignorance but shouldn't all these run under a single transaction ? In the sense, if the third Query runs into an Exception, shouldn't the first & second rollback too ? This doesn't happen in my case. Will hibernate auto commit setting affect the txn boundaries in any way ? Auto commit is set to true in my case. What I require is the commit should take place in any of these tables only if all are successful.
Upvotes: 0
Views: 3764
Reputation: 1127
Yes, the Hibernate connection.autocommit
property setting will affect transaction boundaries.
If you set this to true
, Hibernate will put the underlying JDBC connection in autocommit mode, which will wrap each statement you execute in its own database transaction.
So, for example, if your third query/statement fails, only your third query/statement will get rolled back.
To execute all three as a single unit, you need to have autocommit off and execute all three in the context of a single transaction, declarative or otherwise.
Upvotes: 0
Reputation: 47243
You definitely don't want autocommit on. That will probably commit after every operation. Switch autocommit off, and add an explicit commit at the end.
Upvotes: 0
Reputation: 11
could you try to add one more layer higher than service layer and start transaction from there.
Upvotes: 1