Extended session for transactions

What is Advanced Antipattern Session?

+2


source to share


1 answer


An extended (or long lasting) session (or session for each session ) is a session that can take the time of a transaction, as opposed to sessions with a transaction (or session per-request). This is not necessarily an anti-pattern, it is a way to implement long conversations (i.e. database conversations than multiple transactions), which are just a different way of designing units of work.

Like nothing, I would simply say that lengthy conversations can be misused or mistakenly implemented.

This is how the documentation introduces long conversations:

12.1.2. Long conversations

The session pattern per request is not the only way to design work units. Many business processes require a whole series of user interactions, alternating with database access. On the Internet and corporate applications, it is not acceptable for a database transaction to interact with the user. Consider in the following example:

  • The first screen of the dialog will open. The data seen by the user has been loaded into a specific session and database transaction. The user is free to modify objects.
  • The user clicks the "Save" button after 5 minutes and expects the changes to be permanent. The user also expects that they were the only person editing this information and that no conflicting modifications have occurred.

From the user's point of view, we call this unit of work long-term conversation or expression transaction. There are many ways to implement this in your application.

The first naive implementation can keep the session and database transaction open while the user is viewing the time, with the locks in the database to prevent concurrent modification and to ensure isolation and atomicity. This is an anti-pattern because an assertion lock would prevent the application from scaling with a number of concurrent users.

You need to use multiple transaction databases to implement the conversation. In this case, maintaining the isolation of the business processes becomes a partial responsibility of the application tier. Typically, one conversation spans multiple database transactions. It will be atomic if only one of these database transactions (the last one) stores the updated data. Everyone else just read the data (for example into a wizard style dialog spanning multiple request / response cycles). It's easier to implement than sound can, especially if you're using some of the Hibernate features:

  • Automatic versioning: Hibernate can do automatic concurrency optimization for you. It can automatically detect if a change happened during the user's think time. Check it out at the end of the conversation.
  • Single Objects: If you choose to use the session pattern per request, all loaded instances will be in a remote state during user time. Hibernate allows objects to be reconnected and changes persist. The pattern is called Session-by-Request with detached-objects. Automatic versioning is used to isolate concurrent modifications.
  • Extended (or long) session: A Hibernate session can be disconnected from the underlying JDBC connection after database transactions have been committed and reconnected when a new client request arises. This pattern is known as conversation session and makes even re-binding unnecessary. Automatic versioning is used to isolate concurrent changes and the session will not be allowed to be automatically reset, but explicitly.

And session-by-request with-detached-objects and session-to-talk advantages and disadvantages . These disadvantages are discussed later in this chapter in the context of optimistic concurrency control.



I've added a few links below, but I suggest reading the whole Chapter 12. Transactions and Concurrency .

Links

+5


source







All Articles