读书人

hibernate session 治理

发布时间: 2012-08-02 11:35:26 作者: rapoo

hibernate session 管理

1. Session per Operation (Anti pattern)

?

2. Session per Request

use "Open Session In View" when rendering layer seperate from servlet, e.g. in JSP

?

3. Session per Request with detached object

when a user case spans several transaction, considering the user think time, we can detach and re-attach

the object to different session. Here we mean one session on transaction. For making sure only one user modifying that data, we need to user optimistic lock such as automatic versioning to isolate business use case.

?

4. Session per Conversation

the Hibernate Session can be disconnected from the underlying JDBC connection after the database transaction has been committed and reconnected when a new client request occurs. This pattern is known as session-per-conversation and makes even reattachment unnecessary. Automatic versioning is used to isolate concurrent modifications and the Session will not be allowed to be flushed automatically, but explicitly.

读书人网 >开源软件

热点推荐