Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

There's a lot of information here, so here's an attempt to boil it down into some practical advice:

  1. All hibernate operations should must take place within a transaction.
  2. Care should be taken to identify "units of work" and make sure a single transaction is defined around each unit.
  3. This may mean declaring a transaction around each controller method that responds to an HTTP request.
  4. We should not use the TransactionProxyFactoryBean method of configuring transactions.
  5. We should use AOP for configuring transactions in the service layer and below.
  6. We can use AOP or @Transactional for configuring transactions in the controller layer. Any given app should choose one of these methods and use it consistently.
  7. We should think about what kinds of exceptions should trigger a transaction rollback, and configure the transactions appropriately. By default, checked exceptions will NOT roll back a transaction.
  8. We can control which exceptions force a rollback.
  9. We need to be aware that dirty persistent objects WILL trigger database updates and commits unless a transaction is rolled back by the throwing of an exception.
  10. We should use the default transaction propagation setting (REQUIRED) unless there is a clear reason for using a different setting.
  11. Flush modes still need to be discussed.