public abstract class AbstractEntityManagerImpl extends Object implements HibernateEntityManagerImplementor, Serializable
| Modifier and Type | Class and Description |
|---|---|
static class |
AbstractEntityManagerImpl.TupleBuilderTransformer |
HibernateEntityManagerImplementor.Options| Modifier and Type | Field and Description |
|---|---|
protected PersistenceContextType |
persistenceContextType |
protected TransactionImpl |
tx |
| Modifier | Constructor and Description |
|---|---|
protected |
AbstractEntityManagerImpl(EntityManagerFactoryImpl entityManagerFactory,
PersistenceContextType type,
PersistenceUnitTransactionType transactionType,
Map properties) |
| Modifier and Type | Method and Description |
|---|---|
void |
clear()
Clear the persistence context, causing all managed
entities to become detached.
|
boolean |
contains(Object entity)
Check if the instance is a managed entity instance belonging
to the current persistence context.
|
RuntimeException |
convert(HibernateException e)
Converts a Hibernate-specific exception into a JPA-specified exception; note that the JPA sepcification makes use
of exceptions outside its exception hierarchy, though they are all runtime exceptions.
|
RuntimeException |
convert(HibernateException e,
LockOptions lockOptions)
Converts a Hibernate-specific exception into a JPA-specified exception; note that the JPA sepcification makes use
of exceptions outside its exception hierarchy, though they are all runtime exceptions.
|
RuntimeException |
convert(RuntimeException e) |
Query |
createNamedQuery(String name)
Create an instance of
Query for executing a named query
(in the Java Persistence query language or in native SQL). |
<T> TypedQuery<T> |
createNamedQuery(String name,
Class<T> resultClass)
Create an instance of
TypedQuery for executing a
Java Persistence query language named query. |
Query |
createNativeQuery(String sqlString)
Create an instance of
Query for executing
a native SQL statement, e.g., for update or delete. |
Query |
createNativeQuery(String sqlString,
Class resultClass)
Create an instance of
Query for executing
a native SQL query. |
Query |
createNativeQuery(String sqlString,
String resultSetMapping)
Create an instance of
Query for executing
a native SQL query. |
<T> TypedQuery<T> |
createQuery(CriteriaQuery<T> criteriaQuery)
Create an instance of
TypedQuery for executing a
criteria query. |
Query |
createQuery(String jpaqlString)
Create an instance of
Query for executing a
Java Persistence query language statement. |
<T> TypedQuery<T> |
createQuery(String jpaqlString,
Class<T> resultClass)
Create an instance of
TypedQuery for executing a
Java Persistence query language statement. |
<T> TypedQuery<T> |
createQuery(String jpaqlString,
Class<T> resultClass,
Selection selection,
HibernateEntityManagerImplementor.Options options)
Used during "compiling" a JPA criteria query.
|
void |
detach(Object entity)
Remove the given entity from the persistence context, causing
a managed entity to become detached.
|
CacheMode |
determineAppropriateLocalCacheMode(Map<String,Object> localProperties) |
<A> A |
find(Class<A> entityClass,
Object primaryKey)
Find by primary key.
|
<A> A |
find(Class<A> entityClass,
Object primaryKey,
LockModeType lockModeType)
Find by primary key and lock.
|
<A> A |
find(Class<A> entityClass,
Object primaryKey,
LockModeType lockModeType,
Map<String,Object> properties)
Find by primary key and lock, using the specified properties.
|
<T> T |
find(Class<T> entityClass,
Object primaryKey,
Map<String,Object> properties)
Find by primary key, using the specified properties.
|
void |
flush()
Synchronize the persistence context to the
underlying database.
|
CriteriaBuilder |
getCriteriaBuilder()
Return an instance of
CriteriaBuilder for the creation of
CriteriaQuery objects. |
Object |
getDelegate()
returns the underlying session
|
EntityManagerFactoryImpl |
getEntityManagerFactory()
Return the entity manager factory for the entity manager.
|
HibernateEntityManagerFactory |
getFactory()
Get access to the Hibernate extended EMF contract.
|
FlushModeType |
getFlushMode()
Hibernate can be set in various flush modes that are unknown to
JPA 2.0.
|
LockModeType |
getLockMode(Object entity)
Get the current lock mode for the entity instance.
|
LockOptions |
getLockRequest(LockModeType lockModeType,
Map<String,Object> properties)
Convert from JPA 2
LockModeType & properties into LockOptions |
Metamodel |
getMetamodel()
Return an instance of
Metamodel interface for access to the
metamodel of the persistence unit. |
Map<String,Object> |
getProperties()
Get the properties and hints and associated values that are in effect
for the entity manager.
|
protected abstract Session |
getRawSession()
Return a Session (even if the entity manager is closed).
|
<T> T |
getReference(Class<T> entityClass,
Object primaryKey)
Get an instance, whose state may be lazily fetched.
|
abstract Session |
getSession()
return a Session
|
EntityTransaction |
getTransaction()
Return the resource-level
EntityTransaction object. |
PersistenceUnitTransactionType |
getTransactionType() |
void |
handlePersistenceException(PersistenceException e)
Handles marking for rollback and other such operations that need to occur depending on the type of
exception being handled.
|
boolean |
isTransactionInProgress()
Provides access to whether a transaction is currently in progress.
|
void |
joinTransaction()
Indicate to the entity manager that a JTA transaction is
active.
|
void |
lock(Object entity,
LockModeType lockMode)
Lock an entity instance that is contained in the persistence
context with the specified lock mode type.
|
void |
lock(Object entity,
LockModeType lockModeType,
Map<String,Object> properties)
Lock an entity instance that is contained in the persistence
context with the specified lock mode type and with specified
properties.
|
protected void |
markAsRollback() |
<A> A |
merge(A entity)
Merge the state of the given entity into the
current persistence context.
|
void |
persist(Object entity)
Make an instance managed and persistent.
|
protected void |
postInit() |
void |
refresh(Object entity)
Refresh the state of the instance from the database,
overwriting changes made to the entity, if any.
|
void |
refresh(Object entity,
LockModeType lockModeType)
Refresh the state of the instance from the database,
overwriting changes made to the entity, if any, and
lock it with respect to given lock mode type.
|
void |
refresh(Object entity,
LockModeType lockModeType,
Map<String,Object> properties)
Refresh the state of the instance from the database,
overwriting changes made to the entity, if any, and
lock it with respect to given lock mode type and with
specified properties.
|
void |
refresh(Object entity,
Map<String,Object> properties)
Refresh the state of the instance from the database, using
the specified properties, and overwriting changes made to
the entity, if any.
|
void |
remove(Object entity)
Remove the entity instance.
|
void |
setFlushMode(FlushModeType flushModeType)
Set the flush mode that applies to all objects contained
in the persistence context.
|
void |
setProperty(String s,
Object o)
Set an entity manager property or hint.
|
void |
throwPersistenceException(HibernateException e)
Delegates to
HibernateEntityManagerImplementor.convert(org.hibernate.HibernateException, org.hibernate.LockOptions) and then throws the given exception. |
void |
throwPersistenceException(PersistenceException e)
Delegates to
HibernateEntityManagerImplementor.handlePersistenceException(javax.persistence.PersistenceException) and then throws the given exception. |
<T> T |
unwrap(Class<T> clazz)
Return an object of the specified type to allow access to the
provider-specific API.
|
PersistenceException |
wrapLockException(HibernateException e,
LockOptions lockOptions) |
PersistenceException |
wrapStaleStateException(StaleStateException e) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitclose, isOpenprotected transient TransactionImpl tx
protected PersistenceContextType persistenceContextType
protected AbstractEntityManagerImpl(EntityManagerFactoryImpl entityManagerFactory, PersistenceContextType type, PersistenceUnitTransactionType transactionType, Map properties)
public PersistenceUnitTransactionType getTransactionType()
protected void postInit()
public Query createQuery(String jpaqlString)
EntityManagerQuery for executing a
Java Persistence query language statement.createQuery in interface EntityManagerjpaqlString - a Java Persistence query stringpublic <T> TypedQuery<T> createQuery(String jpaqlString, Class<T> resultClass)
EntityManagerTypedQuery for executing a
Java Persistence query language statement.
The select list of the query must contain only a single
item, which must be assignable to the type specified by
the resultClass argument.createQuery in interface EntityManagerjpaqlString - a Java Persistence query stringresultClass - the type of the query resultpublic <T> TypedQuery<T> createQuery(String jpaqlString, Class<T> resultClass, Selection selection, HibernateEntityManagerImplementor.Options options)
HibernateEntityManagerImplementorcreateQuery in interface HibernateEntityManagerImplementorT - The query typejpaqlString - The criteria query rendered as a JPA QL stringresultClass - The result type (the type expected in the result list)selection - The selection(s)options - The options to use to build the query.public <T> TypedQuery<T> createQuery(CriteriaQuery<T> criteriaQuery)
EntityManagerTypedQuery for executing a
criteria query.createQuery in interface EntityManagercriteriaQuery - a criteria query objectpublic Query createNamedQuery(String name)
EntityManagerQuery for executing a named query
(in the Java Persistence query language or in native SQL).createNamedQuery in interface EntityManagername - the name of a query defined in metadatapublic <T> TypedQuery<T> createNamedQuery(String name, Class<T> resultClass)
EntityManagerTypedQuery for executing a
Java Persistence query language named query.
The select list of the query must contain only a single
item, which must be assignable to the type specified by
the resultClass argument.createNamedQuery in interface EntityManagername - the name of a query defined in metadataresultClass - the type of the query resultpublic Query createNativeQuery(String sqlString)
EntityManagerQuery for executing
a native SQL statement, e.g., for update or delete.createNativeQuery in interface EntityManagersqlString - a native SQL query stringpublic Query createNativeQuery(String sqlString, Class resultClass)
EntityManagerQuery for executing
a native SQL query.createNativeQuery in interface EntityManagersqlString - a native SQL query stringresultClass - the class of the resulting instance(s)public Query createNativeQuery(String sqlString, String resultSetMapping)
EntityManagerQuery for executing
a native SQL query.createNativeQuery in interface EntityManagersqlString - a native SQL query stringresultSetMapping - the name of the result set mappingpublic <T> T getReference(Class<T> entityClass, Object primaryKey)
EntityManagerEntityNotFoundException is thrown when the instance
state is first accessed. (The persistence provider runtime is
permitted to throw the EntityNotFoundException when
getReference is called.)
The application should not expect that the instance state will
be available upon detachment, unless it was accessed by the
application while the entity manager was open.getReference in interface EntityManagerentityClass - entity classprimaryKey - primary keypublic <A> A find(Class<A> entityClass, Object primaryKey)
EntityManagerfind in interface EntityManagerentityClass - entity classprimaryKey - primary keypublic <T> T find(Class<T> entityClass, Object primaryKey, Map<String,Object> properties)
EntityManagerfind in interface EntityManagerentityClass - entity classprimaryKey - primary keyproperties - standard and vendor-specific properties
and hintspublic <A> A find(Class<A> entityClass, Object primaryKey, LockModeType lockModeType)
EntityManager If the entity is found within the persistence context and the
lock mode type is pessimistic and the entity has a version
attribute, the persistence provider must perform optimistic
version checks when obtaining the database lock. If these
checks fail, the OptimisticLockException will be thrown.
If the lock mode type is pessimistic and the entity instance is found but cannot be locked:
PessimisticLockException will be thrown if the database
locking failure causes transaction-level rollback
LockTimeoutException will be thrown if the database
locking failure causes only statement-level rollback
find in interface EntityManagerentityClass - entity classprimaryKey - primary keylockModeType - lock modepublic <A> A find(Class<A> entityClass, Object primaryKey, LockModeType lockModeType, Map<String,Object> properties)
EntityManager If the entity is found
within the persistence context and the lock mode type
is pessimistic and the entity has a version attribute, the
persistence provider must perform optimistic version checks
when obtaining the database lock. If these checks fail,
the OptimisticLockException will be thrown.
If the lock mode type is pessimistic and the entity instance is found but cannot be locked:
PessimisticLockException will be thrown if the database
locking failure causes transaction-level rollback
LockTimeoutException will be thrown if the database
locking failure causes only statement-level rollback
If a vendor-specific property or hint is not recognized, it is silently ignored.
Portable applications should not rely on the standard timeout hint. Depending on the database in use and the locking mechanisms used by the provider, the hint may or may not be observed.
find in interface EntityManagerentityClass - entity classprimaryKey - primary keylockModeType - lock modeproperties - standard and vendor-specific properties
and hintspublic CacheMode determineAppropriateLocalCacheMode(Map<String,Object> localProperties)
public void persist(Object entity)
EntityManagerpersist in interface EntityManagerentity - entity instancepublic <A> A merge(A entity)
EntityManagermerge in interface EntityManagerentity - entity instancepublic void remove(Object entity)
EntityManagerremove in interface EntityManagerentity - entity instancepublic void refresh(Object entity)
EntityManagerrefresh in interface EntityManagerentity - entity instancepublic void refresh(Object entity, Map<String,Object> properties)
EntityManagerIf a vendor-specific property or hint is not recognized, it is silently ignored.
refresh in interface EntityManagerentity - entity instanceproperties - standard and vendor-specific properties
and hintspublic void refresh(Object entity, LockModeType lockModeType)
EntityManagerIf the lock mode type is pessimistic and the entity instance is found but cannot be locked:
PessimisticLockException will be thrown if the database
locking failure causes transaction-level rollback
LockTimeoutException will be thrown if the
database locking failure causes only statement-level
rollback.
refresh in interface EntityManagerentity - entity instancelockModeType - lock modepublic void refresh(Object entity, LockModeType lockModeType, Map<String,Object> properties)
EntityManagerIf the lock mode type is pessimistic and the entity instance is found but cannot be locked:
PessimisticLockException will be thrown if the database
locking failure causes transaction-level rollback
LockTimeoutException will be thrown if the database
locking failure causes only statement-level rollback
If a vendor-specific property or hint is not recognized, it is silently ignored.
Portable applications should not rely on the standard timeout hint. Depending on the database in use and the locking mechanisms used by the provider, the hint may or may not be observed.
refresh in interface EntityManagerentity - entity instancelockModeType - lock modeproperties - standard and vendor-specific properties
and hintspublic boolean contains(Object entity)
EntityManagercontains in interface EntityManagerentity - entity instancepublic LockModeType getLockMode(Object entity)
EntityManagergetLockMode in interface EntityManagerentity - entity instancepublic void setProperty(String s, Object o)
EntityManagersetProperty in interface EntityManagers - name of property or hinto - value for property or hintpublic Map<String,Object> getProperties()
EntityManagergetProperties in interface EntityManagerpublic void flush()
EntityManagerflush in interface EntityManagerpublic abstract Session getSession()
getSession in interface HibernateEntityManagerIllegalStateException - if the entity manager is closedprotected abstract Session getRawSession()
public EntityTransaction getTransaction()
EntityManagerEntityTransaction object.
The EntityTransaction instance may be used serially to
begin and commit multiple transactions.getTransaction in interface EntityManagerpublic EntityManagerFactoryImpl getEntityManagerFactory()
getEntityManagerFactory in interface EntityManagerpublic HibernateEntityManagerFactory getFactory()
getFactory in interface HibernateEntityManagerImplementorpublic CriteriaBuilder getCriteriaBuilder()
CriteriaBuilder for the creation of
CriteriaQuery objects.getCriteriaBuilder in interface EntityManagerpublic Metamodel getMetamodel()
Metamodel interface for access to the
metamodel of the persistence unit.getMetamodel in interface EntityManagerpublic void setFlushMode(FlushModeType flushModeType)
EntityManagersetFlushMode in interface EntityManagerflushModeType - flush modepublic void clear()
EntityManagerclear in interface EntityManagerpublic void detach(Object entity)
EntityManagerdetach in interface EntityManagerentity - entity instancepublic FlushModeType getFlushMode()
getFlushMode in interface EntityManagerpublic void lock(Object entity, LockModeType lockMode)
EntityManagerIf a pessimistic lock mode type is specified and the entity
contains a version attribute, the persistence provider must
also perform optimistic version checks when obtaining the
database lock. If these checks fail, the
OptimisticLockException will be thrown.
If the lock mode type is pessimistic and the entity instance is found but cannot be locked:
PessimisticLockException will be thrown if the database
locking failure causes transaction-level rollback
LockTimeoutException will be thrown if the database
locking failure causes only statement-level rollback
lock in interface EntityManagerentity - entity instancelockMode - lock modepublic void lock(Object entity, LockModeType lockModeType, Map<String,Object> properties)
EntityManagerIf a pessimistic lock mode type is specified and the entity
contains a version attribute, the persistence provider must
also perform optimistic version checks when obtaining the
database lock. If these checks fail, the
OptimisticLockException will be thrown.
If the lock mode type is pessimistic and the entity instance is found but cannot be locked:
PessimisticLockException will be thrown if the database
locking failure causes transaction-level rollback
LockTimeoutException will be thrown if the database
locking failure causes only statement-level rollback
If a vendor-specific property or hint is not recognized, it is silently ignored.
Portable applications should not rely on the standard timeout hint. Depending on the database in use and the locking mechanisms used by the provider, the hint may or may not be observed.
lock in interface EntityManagerentity - entity instancelockModeType - lock modeproperties - standard and vendor-specific properties
and hintspublic LockOptions getLockRequest(LockModeType lockModeType, Map<String,Object> properties)
HibernateEntityManagerImplementorLockModeType & properties into LockOptionsgetLockRequest in interface HibernateEntityManagerImplementorlockModeType - is the requested lock typeproperties - are the lock propertiespublic boolean isTransactionInProgress()
HibernateEntityManagerImplementorisTransactionInProgress in interface HibernateEntityManagerImplementorprotected void markAsRollback()
public void joinTransaction()
EntityManagerjoinTransaction in interface EntityManagerpublic <T> T unwrap(Class<T> clazz)
EntityManagerEntityManager
implementation does not support the specified class, the
PersistenceException is thrown.unwrap in interface EntityManagerclazz - the class of the object to be returned. This is
normally either the underlying EntityManager implementation
class or an interface that it implements.public Object getDelegate()
getDelegate in interface EntityManagerpublic void handlePersistenceException(PersistenceException e)
handlePersistenceException in interface HibernateEntityManagerImplementore - The exception being handled.public void throwPersistenceException(PersistenceException e)
HibernateEntityManagerImplementor.handlePersistenceException(javax.persistence.PersistenceException) and then throws the given exception.throwPersistenceException in interface HibernateEntityManagerImplementore - The exception being handled and finally thrown.public RuntimeException convert(HibernateException e)
HibernateEntityManagerImplementor.handlePersistenceException(javax.persistence.PersistenceException) are also made.convert in interface HibernateEntityManagerImplementore - The Hibernate excepton.public RuntimeException convert(RuntimeException e)
public RuntimeException convert(HibernateException e, LockOptions lockOptions)
HibernateEntityManagerImplementor.handlePersistenceException(javax.persistence.PersistenceException) are also made.convert in interface HibernateEntityManagerImplementore - The Hibernate excepton.lockOptions - The lock options in effect at the time of exception (can be null)public void throwPersistenceException(HibernateException e)
HibernateEntityManagerImplementor.convert(org.hibernate.HibernateException, org.hibernate.LockOptions) and then throws the given exception.throwPersistenceException in interface HibernateEntityManagerImplementore - The exception being handled and finally thrown.public PersistenceException wrapStaleStateException(StaleStateException e)
wrapStaleStateException in interface HibernateEntityManagerImplementorpublic PersistenceException wrapLockException(HibernateException e, LockOptions lockOptions)
Copyright © 2012 JBoss by Red Hat. All Rights Reserved.