For persistent data that is ony occasionaly updated, you can implement a "read-mostly pattern" in WebLogic Server by mapping a read-only and a read-write entity bean to the same data. You use the read-only entity bean for reads and the read-write entity bean for writes.
The read-only entity EJB loads bean data at intervals specified by the read-timeout-seconds element in the entity-catch(or entity-cache-ref) stanza for the bean in weblogic-ejb-jar.xml. To ensure that the read-only bean always returns current data, the read-only bean must be invalidated when the read-write bean changes the entity bean data. You can configure WebLogic Server to automatically invalidate the read-only bean, or explicitly invaidate it in bean code, as described in Invalidating Read-Only Entity EJBs Implicitly and Invalidating Read-Only Entity EJBs Explicitly respectively.
In a WebLogic Server cluster, the read-mostly pattern gives clients of the read-only EJB the performance advantage of reading from cache, while clients of read-write EJB enjoy true transactional behavior---the read-write EJB's cached state always matches theh persistent data in the database.
Invalidating Read-Only Entity EJBs Implicity
The invalidation-target element in the entity-descriptor
stanza in weblogic-ejb-jar.xml
identifies a read-only entity EJB that should be invalidated when a CMP entity bean has been modified.
invalidation-target
may only be specified for an EJB 2.0 CMP entity bean. The target ejb-name must be a read-only entity EJB.
Invalidating Read-Only Entity EJBs Explicitly
Invalidate a read-only entity bean by calling the following invalidate()
method on either the CachingHome
or CachingLocalHome
interface.
Listing 6-10 CachingHome and CachingLocalHome interfaces
package weblogic.ejb;
public interface CachingHome {
public void invalidate(Object pk) throws RemoteException;
public void invalidate (Collection pks) throws RemoteException;
public void invalidateAll() throws RemoteException;
public interface CachingLocalHome {
public void invalidate(Object pk) throws RemoteException;
public void invalidate (Collection pks) throws RemoteException;
public void invalidateAll() throws RemoteException
}