concept change in category seam

This is an excerpt from Manning's book Seam in Action.
Seam takes control of the persistence manager and stores it in the conversation context. As a result, Seam is able to carry it, along with its persistence context, across the duration of an entire use case, potentially spanning more than one request, as shown in figure 1.9. Extending the persistence context across the three operations in this feature allows the entity instance to remain managed by the persistence context and monitored for changes that need to be written to the database. This ensures object identity and can guarantee atomicity of the operation.
Managed persistence has a history of being at odds with sound object-oriented design. EJB 2 championed the use of distributed objects. As a consequence, developers quickly resorted to using data transfer objects (DTOs) to push aggregated data over the wire as a way to reduce network traffic. These domain objects were void of behavior. Unfortunately, the intelligence in domain objects didn’t get restored once “lightweight” DAO frameworks replaced EJB 2 because the same flawed architecture was adopted. Treating domain objects as buckets for holding data, without giving them real behavior, is an anti-pattern known as the Anemic Domain Model.[3] As is the fate of all things out of balance, a change was imminent.
There’s a side effect to proactively pushing changes onto the managed entity (which occurs in the Update Model Values phase). The changes are flushed to the database before the user has finished editing the record. To avoid that situation, we need to switch to manual flushing.
As you’ll recall from the previous two chapters, the persistence manager flushes the persistence context when the transaction is closed, or possibly sooner. To hold off the changes until the user explicitly requests that they be flushed to the database, we need to enable manual flushing of the persistence context. You can have Seam handle the switch by declaring a flush mode on the <begin-conversation> element in page descriptor (e.g., RoundEdit.page.xml) or on the @Begin annotation. Remember that to use manual flushing, you must be using Hibernate natively or as the JPA provider:
<begin-conversation join="true" flush-mode="manual"/>With this configuration in place, database transactions may come and go, but the changes to the entity instance aren’t migrating to the database until the flush() method on the persistence manager is called. The right time for these changes to be made is when the user clicks the Save, Update, or Delete button, signaling the end of an application transaction. Fortunately, you don’t have to worry about calling flush(). The persist(), update(), and remove() methods on Home take care of flushing the persistence context.