Lzx_longyou2016.01.31 00:27 questions
- Struts2 and Hibernate integrated development framework, how to expand the hibernate session life cycle 10C
Recently, want to learn Struts2, and before Hibernate together to do a project contact. Before using Hibernate framework, in order to solve Hibernate lazy loading problem is the use of OpenSessionInView, the definition of a filter in the filter, open the session, open the transaction. And the try..Catch.., when the time is, can capture filter, then the transaction is rolled back. But now want to add Struts2, Struts2 has a built-in exception handling, this action in the abnormal OpenSessionInView this filter cannot be captured, then the transaction cannot be rolled back. This may lead to business logic error. If you don't use OpenSessionInView, directly open the session in Dao, close session. There will be lazy loading problem. How to solve the master for advice. There is no transaction management using Spring.
My current thinking is to write a Struts2 interceptor myself, starts a transaction in the interceptor, exception handling. Rollback exception is caught, and then thrown out, let the abnormal Struts2 interceptor. There is no other good way?