public interface EntityManager
| Modifier and Type | Method and Description |
|---|---|
void |
clear()
Clear the persistence context, causing all managed entities to become detached.
|
void |
close()
Close an application-managed entity manager.
|
boolean |
contains(Object entity)
Check if the instance is a managed entity instance belonging to the current persistence context.
|
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 qlString)
Create an instance of Query for executing a Java Persistence query language statement.
|
<T> TypedQuery<T> |
createQuery(String qlString,
Class<T> resultClass)
Create an instance of TypedQuery for executing a Java Persistence query language statement.
|
void |
detach(Object entity)
Remove the given entity from the persistence context, causing a managed entity to become detached.
|
<T> T |
find(Class<T> entityClass,
Object primaryKey)
Find by primary key.
|
<T> T |
find(Class<T> entityClass,
Object primaryKey,
LockModeType lockMode)
Find by primary key and lock.
|
<T> T |
find(Class<T> entityClass,
Object primaryKey,
LockModeType lockMode,
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()
Return the underlying provider object for the EntityManager, if available.
|
EntityManagerFactory |
getEntityManagerFactory()
Return the entity manager factory for the entity manager.
|
FlushModeType |
getFlushMode()
Get the flush mode that applies to all objects contained in the persistence context.
|
LockModeType |
getLockMode(Object entity)
Get the current lock mode for the entity instance.
|
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.
|
<T> T |
getReference(Class<T> entityClass,
Object primaryKey)
Get an instance, whose state may be lazily fetched.
|
EntityTransaction |
getTransaction()
Return the resource-level EntityTransaction object.
|
boolean |
isJoinedToTransaction()
Determine whether the entity manager is joined to the current transaction.
|
boolean |
isOpen()
Determine whether the entity manager is open.
|
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 lockMode,
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.
|
<T> T |
merge(T entity)
Merge the state of the given entity into the current persistence context.
|
void |
persist(Object entity)
Make an instance managed and persistent.
|
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 lockMode)
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 lockMode,
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 flushMode)
Set the flush mode that applies to all objects contained in the persistence context.
|
void |
setProperty(String propertyName,
Object value)
Set an entity manager property or hint.
|
<T> T |
unwrap(Class<T> cls)
Return an object of the specified type to allow access to the provider-specific API.
|
void clear()
void close()
IllegalStateException - if the entity manager is container-managedboolean contains(Object entity)
entity - the entity instanceIllegalArgumentException - if not an entityQuery createNamedQuery(String name)
name - the name of a query defined in metadataIllegalArgumentException - if a query has not been defined with the given name or if the query string is found to be invalid<T> TypedQuery<T> createNamedQuery(String name, Class<T> resultClass)
T - query result typename - the name of a query defined in metadataresultClass - the type of the query resultIllegalArgumentException - if a query has not been defined with the given name or if the query string is found to be invalid or if the query result
is found to not be assignable to the specified typeQuery createNativeQuery(String sqlString)
sqlString - a native SQL query stringQuery createNativeQuery(String sqlString, Class<?> resultClass)
sqlString - a native SQL query stringresultClass - the class of the resulting instance(s)Query createNativeQuery(String sqlString, String resultSetMapping)
sqlString - a native SQL query stringresultSetMapping - the name of the result set mapping<T> TypedQuery<T> createQuery(CriteriaQuery<T> criteriaQuery)
T - query result typecriteriaQuery - a criteria query objectIllegalArgumentException - if the criteria query is found to be invalidQuery createQuery(String qlString)
qlString - a Java Persistence query stringIllegalArgumentException - if the query string is found to be invalid<T> TypedQuery<T> createQuery(String qlString, Class<T> resultClass)
T - query result typeqlString - a Java Persistence query stringresultClass - the type of the query resultIllegalArgumentException - if the query string is found to be invalid or if the query result is found to not be assignable to the specified typevoid detach(Object entity)
entity - the entity instanceIllegalArgumentException - if the instance is not an entity<T> T find(Class<T> entityClass, Object primaryKey)
T - the object type of the entityentityClass - the class of the entityprimaryKey - the primary keyIllegalArgumentException - if the first argument does not denote an entity type or the second argument is is not a valid type for that entity’s
primary key or is null<T> T find(Class<T> entityClass, Object primaryKey, LockModeType lockMode)
T - the object type of the entityentityClass - the class of the entityprimaryKey - the primary keylockMode - the lock modeIllegalArgumentException - if the first argument does not denote an entity type or the second argument is not a valid type for that entity's primary
key or is nullTransactionRequiredException - if there is no transaction and a lock mode other than NONE is specified or if invoked on an entity manager which has not
been joined to the current transaction and a lock mode other than NONE is specifiedOptimisticLockException - if the optimistic version check failsPessimisticLockException - if pessimistic locking fails and the transaction is rolled backLockTimeoutException - if pessimistic locking fails and only the statement is rolled backPersistenceException - if an unsupported lock call is made<T> T find(Class<T> entityClass, Object primaryKey, LockModeType lockMode, Map<String,Object> properties)
T - the object type of the entityentityClass - the class of the entityprimaryKey - the primary keylockMode - the lock modeproperties - standard and vendor-specific properties and hintsIllegalArgumentException - if the first argument does not denote an entity type or the second argument is not a valid type for that entity's primary
key or is nullTransactionRequiredException - if there is no transaction and a lock mode other than NONE is specified or if invoked on an entity manager which has not
been joined to the current transaction and a lock mode other than NONE is specifiedOptimisticLockException - if the optimistic version check failsPessimisticLockException - if pessimistic locking fails and the transaction is rolled backLockTimeoutException - if pessimistic locking fails and only the statement is rolled backPersistenceException - if an unsupported lock call is made<T> T find(Class<T> entityClass, Object primaryKey, Map<String,Object> properties)
T - the object type of the entityentityClass - the class of the entityprimaryKey - the primary keyproperties - standard and vendor-specific properties and hintsIllegalArgumentException - if the first argument does not denote an entity type or the second argument is is not a valid type for that entity’s
primary key or is nullvoid flush()
TransactionRequiredException - if there is no transaction or if the entity manager has not been joined to the current transactionPersistenceException - if the flush failsCriteriaBuilder getCriteriaBuilder()
IllegalStateException - if the entity manager has been closedObject getDelegate()
EntityManagerFactory getEntityManagerFactory()
IllegalStateException - if the entity manager has been closedFlushModeType getFlushMode()
LockModeType getLockMode(Object entity)
entity - the entity instanceTransactionRequiredException - if there is no transaction or if the entity manager has not been joined to the current transactionIllegalArgumentException - if the instance is not a managed entity and a transaction is activeMetamodel getMetamodel()
IllegalStateException - if the entity manager has been closedMap<String,Object> getProperties()
<T> T getReference(Class<T> entityClass, Object primaryKey)
T - the object type of the entityentityClass - the class of the entityprimaryKey - the primary keyIllegalArgumentException - if the first argument does not denote an entity type or the second argument is not a valid type for that entity’s primary
key or is nullEntityNotFoundException - if the entity state cannot be accessedEntityTransaction getTransaction()
IllegalStateException - if invoked on a JTA entity managerboolean isJoinedToTransaction()
boolean isOpen()
void joinTransaction()
TransactionRequiredException - if there is no transactionvoid lock(Object entity, LockModeType lockMode)
entity - the entity instancelockMode - the lock modeIllegalArgumentException - if the instance is not an entity or is a detached entityTransactionRequiredException - if there is no transaction or if invoked on an entity manager which has not been joined to the current transactionEntityNotFoundException - if the entity does not exist in the database when pessimistic locking is performedOptimisticLockException - if the optimistic version check failsPessimisticLockException - if pessimistic locking fails and the transaction is rolled backLockTimeoutException - if pessimistic locking fails and only the statement is rolled backPersistenceException - if an unsupported lock call is madevoid lock(Object entity, LockModeType lockMode, Map<String,Object> properties)
entity - the entity instancelockMode - the lock modeproperties - standard and vendor-specific properties and hintsIllegalArgumentException - if the instance is not an entity or is a detached entityTransactionRequiredException - if there is no transaction or if invoked on an entity manager which has not been joined to the current transactionEntityNotFoundException - if the entity does not exist in the database when pessimistic locking is performedOptimisticLockException - if the optimistic version check failsPessimisticLockException - if pessimistic locking fails and the transaction is rolled backLockTimeoutException - if pessimistic locking fails and only the statement is rolled backPersistenceException - if an unsupported lock call is made<T> T merge(T entity)
T - the object type of the entityentity - the entity instanceIllegalArgumentException - if instance is not an entity or is a removed entityTransactionRequiredException - if there is no transaction when invoked on a container-managed entity manager that is of type
PersistenceContextType.TRANSACTION.void persist(Object entity)
entity - the entity instanceEntityExistsException - if the entity already exists. (If the entity already exists, the EntityExistsException may be thrown when the persist
operation is invoked, or the EntityExistsException or another PersistenceException may be thrown at flush or commit
time.)IllegalArgumentException - if the instance is not an entityTransactionRequiredException - if there is no transaction when invoked on a container-managed entity manager that is of type
PersistenceContextType.TRANSACTION.void refresh(Object entity)
entity - the entity instanceIllegalArgumentException - if the instance is not an entity or the entity is not managedTransactionRequiredException - if there is no transaction when invoked on a container-managed entity manager that is of type
PersistenceContextType.TRANSACTION.EntityNotFoundException - if the entity no longer exists in the databasevoid refresh(Object entity, LockModeType lockMode)
entity - the entity instancelockMode - the lock modeIllegalArgumentException - if the instance is not an entity or the entity is not managedTransactionRequiredException - if invoked on an entity manager of type PersistenceContextType.TRANSACTION when there is no transaction; if invoked on an
extended entity manager when there is no transaction and a lock mode other than NONE has been specified; or if invoked on
an extended entity manager that has not been joined to the current transaction and a lock mode other than NONE has been
specifiedEntityNotFoundException - if the entity no longer exists in the databasePessimisticLockException - if pessimistic locking fails and the transaction is rolled backLockTimeoutException - if pessimistic locking fails and only the statement is rolled backPersistenceException - if an unsupported lock call is madevoid refresh(Object entity, LockModeType lockMode, Map<String,Object> properties)
entity - the entity instancelockMode - the lock modeproperties - standard and vendor-specific properties and hintsIllegalArgumentException - if the instance is not an entity or the entity is not managedTransactionRequiredException - if invoked on an entity manager of type PersistenceContextType.TRANSACTION when there is no transaction; if invoked on an
extended entity manager when there is no transaction and a lock mode other than NONE has been specified; or if invoked on
an extended entity manager that has not been joined to the current transaction and a lock mode other than NONE has been
specifiedEntityNotFoundException - if the entity no longer exists in the databasePessimisticLockException - if pessimistic locking fails and the transaction is rolled backLockTimeoutException - if pessimistic locking fails and only the statement is rolled backPersistenceException - if an unsupported lock call is madevoid refresh(Object entity, Map<String,Object> properties)
entity - the entity instanceproperties - standard and vendor-specific properties and hintsIllegalArgumentException - if the instance is not an entity or the entity is not managedTransactionRequiredException - if there is no transaction when invoked on a container-managed entity manager that is of type
PersistenceContextType.TRANSACTION.EntityNotFoundException - if the entity no longer exists in the databasevoid remove(Object entity)
entity - the entity instanceIllegalArgumentException - if the instance is not an entity or is a detached entityTransactionRequiredException - if there is no transaction when invoked on a container-managed entity manager that is of type
PersistenceContextType.TRANSACTION.void setFlushMode(FlushModeType flushMode)
flushMode - the flush modevoid setProperty(String propertyName, Object value)
propertyName - name of property or hintvalue - the value of the property or hintIllegalArgumentException - if the second argument is not valid for the implementation<T> T unwrap(Class<T> cls)
T - type of the classcls - the class of the object to be returned. This is normally either the underlying EntityManager implementation class or an
interface that it implements.PersistenceException - if the provider does not support the callCopyright © 2012 Batoo Software & Consultancy. All Rights Reserved.