org.jboss.seam.persistence
Class HibernatePersistenceProvider

java.lang.Object
  extended by org.jboss.seam.persistence.PersistenceProvider
      extended by org.jboss.seam.persistence.HibernatePersistenceProvider

@Name(value="org.jboss.seam.persistence.persistenceProvider")
@Scope(value=STATELESS)
@BypassInterceptors
@Install(precedence=10,
         classDependencies={"org.hibernate.Session","javax.persistence.EntityManager"})
public class HibernatePersistenceProvider
extends PersistenceProvider

Support for non-standardized features of Hibernate, when used as the JPA persistence provider.

Author:
Gavin King, Pete Muir

Nested Class Summary
 
Nested classes/interfaces inherited from class org.jboss.seam.persistence.PersistenceProvider
PersistenceProvider.Feature
 
Field Summary
 
Fields inherited from class org.jboss.seam.persistence.PersistenceProvider
featureSet
 
Constructor Summary
HibernatePersistenceProvider()
           
 
Method Summary
 void enableFilter(Filter f, javax.persistence.EntityManager entityManager)
          Enable a Filter.
 Class getBeanClass(Object bean)
          Returns the class of the specified Hibernate entity
static Class getEntityClass(Object bean)
           
 Object getId(Object bean, javax.persistence.EntityManager entityManager)
          Get the value of the entity identifier attribute.
 String getName(Object bean, javax.persistence.EntityManager entityManager)
          Get the name of the entity
 Object getVersion(Object bean, javax.persistence.EntityManager entityManager)
          Get the value of the entity version attribute.
static Object getVersion(Object value, org.hibernate.Session session)
           
 void checkVersion(Object bean, javax.persistence.EntityManager entityManager, Object oldVersion, Object version)
           
static void checkVersion(Object value, org.hibernate.Session session, Object oldVersion, Object version)
           
 void init()
           
static HibernatePersistenceProvider instance()
           
 boolean isDirty(javax.persistence.EntityManager entityManager)
          Does the persistence context have unflushed changes?
 Object proxyDelegate(Object delegate)
          Wrap the delegate Hibernate Session in a proxy that supports HQL EL interpolation and implements FullTextSession if Hibernate Search is available in the classpath.
 javax.persistence.EntityManager proxyEntityManager(javax.persistence.EntityManager entityManager)
          Wrap the entityManager before returning it to the application
 boolean registerSynchronization(Synchronization sync, javax.persistence.EntityManager entityManager)
          Register a Synchronization with the current transaction.
 void setFlushModeManual(javax.persistence.EntityManager entityManager)
          Set the flush mode to manual-only flushing.
 void setRenderFlushMode()
           Set the FlushMode the persistence contexts should use during rendering by calling PersistenceContexts#changeFlushMode(FlushModeType, true).
 
Methods inherited from class org.jboss.seam.persistence.PersistenceProvider
getPostLoadMethod, getPostLoadMethod, getPrePersistMethod, getPrePersistMethod, getPreRemoveMethod, getPreRemoveMethod, getPreUpdateMethod, getPreUpdateMethod, supportsFeature
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HibernatePersistenceProvider

public HibernatePersistenceProvider()
Method Detail

init

public void init()
Overrides:
init in class PersistenceProvider

proxyDelegate

public Object proxyDelegate(Object delegate)
Wrap the delegate Hibernate Session in a proxy that supports HQL EL interpolation and implements FullTextSession if Hibernate Search is available in the classpath.

Overrides:
proxyDelegate in class PersistenceProvider

setFlushModeManual

public void setFlushModeManual(javax.persistence.EntityManager entityManager)
Description copied from class: PersistenceProvider
Set the flush mode to manual-only flushing. Called when an atomic persistence context is required.

Overrides:
setFlushModeManual in class PersistenceProvider

setRenderFlushMode

public void setRenderFlushMode()
Description copied from class: PersistenceProvider

Set the FlushMode the persistence contexts should use during rendering by calling PersistenceContexts#changeFlushMode(FlushModeType, true). The actual changing of the flush mode is handled by the PersistenceContexts instance. The boolean argument should be true to indicate that this is a temporary change and that the old flush mode should be restored after render.

Ideally, this should be MANUAL since changes should never flush to the database while in render response and the cost of a dirty check can be avoided. However, since the MANUAL mode is not officially part of the JPA specification, the default implementation will perform no operation.

Overrides:
setRenderFlushMode in class PersistenceProvider

isDirty

public boolean isDirty(javax.persistence.EntityManager entityManager)
Description copied from class: PersistenceProvider
Does the persistence context have unflushed changes? If it does not, persistence context replication can be optimized.

Overrides:
isDirty in class PersistenceProvider
Returns:
true to indicate that there are unflushed changes

getId

public Object getId(Object bean,
                    javax.persistence.EntityManager entityManager)
Description copied from class: PersistenceProvider
Get the value of the entity identifier attribute.

Overrides:
getId in class PersistenceProvider
Parameters:
bean - a managed entity instance

getVersion

public Object getVersion(Object bean,
                         javax.persistence.EntityManager entityManager)
Description copied from class: PersistenceProvider
Get the value of the entity version attribute.

Overrides:
getVersion in class PersistenceProvider
Parameters:
bean - a managed entity instance

checkVersion

public void checkVersion(Object bean,
                         javax.persistence.EntityManager entityManager,
                         Object oldVersion,
                         Object version)
Overrides:
checkVersion in class PersistenceProvider

enableFilter

public void enableFilter(Filter f,
                         javax.persistence.EntityManager entityManager)
Description copied from class: PersistenceProvider
Enable a Filter. This is here just especially for Hibernate, since we well know that other products don't have such cool features.

Overrides:
enableFilter in class PersistenceProvider

registerSynchronization

public boolean registerSynchronization(Synchronization sync,
                                       javax.persistence.EntityManager entityManager)
Description copied from class: PersistenceProvider
Register a Synchronization with the current transaction.

Overrides:
registerSynchronization in class PersistenceProvider

getName

public String getName(Object bean,
                      javax.persistence.EntityManager entityManager)
               throws IllegalArgumentException
Description copied from class: PersistenceProvider
Get the name of the entity

Overrides:
getName in class PersistenceProvider
Throws:
IllegalArgumentException - if the passed object is not an entity

proxyEntityManager

public javax.persistence.EntityManager proxyEntityManager(javax.persistence.EntityManager entityManager)
Description copied from class: PersistenceProvider
Wrap the entityManager before returning it to the application

Overrides:
proxyEntityManager in class PersistenceProvider

checkVersion

public static void checkVersion(Object value,
                                org.hibernate.Session session,
                                Object oldVersion,
                                Object version)

getVersion

public static Object getVersion(Object value,
                                org.hibernate.Session session)

getBeanClass

public Class getBeanClass(Object bean)
Returns the class of the specified Hibernate entity

Overrides:
getBeanClass in class PersistenceProvider
Parameters:
bean - The entity bean instance
Returns:
The class of the entity bean

getEntityClass

public static Class getEntityClass(Object bean)

instance

public static HibernatePersistenceProvider instance()