问题
I had been using @Transactional
annotations in my Service Layer. But to resolve an error due to Lazy Loading in View I had to use Open Session in View Filter
. After this, without use of @Transaction itself a Session gets opened and transaction starts. So does that mean @Transactions are not required? How will transactions and roll-backs be handled, then in Service Layers?
回答1:
The javadoc explains it:
This filter makes Hibernate Sessions available via the current thread, which will be autodetected by transaction managers. It is suitable for service layer transactions via HibernateTransactionManager or JtaTransactionManager as well as for non-transactional execution (if configured appropriately).
NOTE: This filter will by default not flush the Hibernate Session, with the flush mode set to FlushMode.NEVER. It assumes to be used in combination with service layer transactions that care for the flushing: The active transaction manager will temporarily change the flush mode to FlushMode.AUTO during a read-write transaction, with the flush mode reset to FlushMode.NEVER at the end of each transaction. If you intend to use this filter without transactions, consider changing the default flush mode (through the "flushMode" property).
来源:https://stackoverflow.com/questions/16465269/open-session-in-view-vs-transactional