concept entity in category jboss

appears as: entities, n entity, entity, entity, entities
JBoss in Action: Configuring the JBoss Application Server

This is an excerpt from Manning's book JBoss in Action: Configuring the JBoss Application Server.

Entities are objects that represent domain objects mapped to the database. Entity persistence is either encapsulated by a database transaction or part of a larger business transaction. Message-driven beans are asynchronous message consumers managed by a container.

After providing this configuration, you can tell an entity to participate in the cache by annotating the entity class. To annotate a class, you must use the @org.hibernate.annotations.Cache annotation. The following code shows a class called Category that is annotated with the @Cache annotation:

@Entity
@Table(name="CATEGORIES")
@Cache(usage=CacheConcurrencyStrategy.READ_ONLY)
public class Category implements Serializable {
private Long jpaId;
private String categoryName;
// ...
}

Notice that the annotation takes an argument called usage of type @org.hibernate. annotations.CacheConcurrencyStrategy, which tells Hibernate how to treat entities of this type in the cache. The options supported by JBoss Cache are shown in table 13.6.

Table 13.6. The available CacheConcurrencyStrategy options you can assign to an entity

CacheConcurrencyStrategy value

Description

READ_ONLY

Use this option if your data never changes. Once the entity is in the cache, it isn’t retrieved again unless the cache is manually evicted.

READ_WRITE

Use this option to cache data that’s occasionally updated, but where isolation is necessary to avoid stale data. This strategy ensures read-committed isolation by maintaining a timestamp for the entity.

NONSTRICT_READ_WRITE

Use this option to cache data that’s occasionally updated, but where some stale data can be tolerated. This mode gives no guarantee of isolation, but is faster than READ_WRITE.

TRANSACTIONAL

Guarantees full transactional isolation up to repeatable read. Use this option for data that’s mostly read but where it’s critical to prevent stale data if an update does occur.

13.4. Clustering entities

In previous versions of EJB, entity beans were remotely accessible (even though it wasn’t generally recommended). In JPA, entities aren’t accessible remotely, so you wouldn’t cluster entities for the purpose of load balancing; but we do care about state replication and high availability.