0

This answer gives a solid explanation of merge v. persist in Hibernate.

Let's say that I'm calling merge(foo) in the following example:

Foo foo = new Foo();
session.merge(foo);

Since we don't know what's in Foo, this merge could result in 1 or more SQL transactions to perform this operation.

For this example, let's say merge(foo) results in 3 SQL transactions. If the first 2 transactions succeed, but the third fails, will Hibernate automatically rollback all 3 transactions?

Community
  • 1
  • 1
Kevin Meredith
  • 41,036
  • 63
  • 209
  • 384
  • A call to merge() never results in transactions. You are responsible for starting and committing transactions. The session methods do their work in the current transaction that you have started. – JB Nizet Aug 21 '14 at 22:03
  • @JBNizet, do you usually use `@Transactional` in Spring to rollback any commits made if an exception occurred? Thanks – Kevin Meredith Aug 21 '14 at 22:10
  • Yes. Declarative transaction handling is much cleaner, safer and readable than programmatic transaction handling. – JB Nizet Aug 21 '14 at 22:12

0 Answers0