...
There's a lot of information here, so here's an attempt to boil it down into some practical advice:
- All hibernate operations should must take place within a transaction.
- Care should be taken to identify "units of work" and make sure a single transaction is defined around each unit.
- This may mean declaring a transaction around each controller method that responds to an HTTP request.
- We should not use the TransactionProxyFactoryBean method of configuring transactions.
- We should use AOP for configuring transactions in the service layer and below.
- 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.
- 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.
- We can control which exceptions force a rollback.
- 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.
- We should use the default transaction propagation setting (REQUIRED) unless there is a clear reason for using a different setting.
- Flush modes still need to be discussed.