Web hosting ratings - CHAPTER 9 Working with objects We ll also get

CHAPTER 9 Working with objects We ll also get back to the synchronization process (known as flushing) and when it occurs later in this chapter. The persistence context cache A persistence context is a cache of persistent entity instances. This means it remembers all persistent entity instances you ve handled in a particular unit of work. Automatic dirty checking is one of the benefits of this caching. Another benefit is repeatable read for entities and the performance advantage of a unit of work-scoped cache. For example, if Hibernate is told to load an object by primary key (a lookup by identifier), it can first check the persistence context for the current unit of work. If the entity is found there, no database hit occurs this is a repeatable read for an application. The same is true if a query is executed through one of the Hibernate (or Java Persistence) interfaces. Hibernate reads the result set of the query and marshals entity objects that are then returned to the application. During this process, Hibernate interacts with the current persistence context. It tries to resolve every entity instance in this cache (by identifier); only if the instance can t be found in the current persistence context does Hibernate read the rest of the data from the result set. The persistence context cache offers significant performance benefits and improves the isolation guarantees in a unit of work (you get repeatable read of entity instances for free). Because this cache only has the scope of a unit of work, it has no real disadvantages, such as lock management for concurrent access a unit of work is processed in a single thread at a time. The persistence context cache sometimes helps avoid unnecessary database traffic; but, more important, it ensures that: The persistence layer isn t vulnerable to stack overflows in the case of circular references in a graph of objects. There can never be conflicting representations of the same database row at the end of a unit of work. In the persistence context, at most a single object represents any database row. All changes made to that object may be safely written to the database. Likewise, changes made in a particular persistence context are always immediately visible to all other code executed inside that persistence context and its unit of work (the repeatable read for entities guarantee). You don t have to do anything special to enable the persistence context cache. It s always on and, for the reasons shown, can t be turned off.
Looking for affordable and reliable webhost to host and run your business application? Then look no more and go to servlet web hosting services.

Leave a Reply