|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
public interface EntityManager
Interface used to interact with the persistence context.
| Method Summary | ||
|---|---|---|
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). |
|
|
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. |
|
|
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. |
|
|
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. |
|
|
find(Class<T> entityClass,
Object primaryKey)
Find by primary key. |
|
|
find(Class<T> entityClass,
Object primaryKey,
LockModeType lockMode)
Find by primary key and lock. |
|
|
find(Class<T> entityClass,
Object primaryKey,
LockModeType lockMode,
Map<String,Object> properties)
Find by primary key and lock, using the specified properties. |
|
|
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. |
|
|
getReference(Class<T> entityClass,
Object primaryKey)
Get an instance, whose state may be lazily fetched. |
|
EntityTransaction |
getTransaction()
Return the resource-level EntityTransaction object. |
|
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. |
|
|
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. |
|
|
unwrap(Class<T> cls)
Return an object of the specified type to allow access to the provider-specific API. |
|
| Method Detail |
|---|
void persist(Object entity)
entity -
EntityExistsException - 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 entity
TransactionRequiredException - if invoked on a container-managed entity manager of type
PersistenceContextType.TRANSACTION and there is no transaction<T> T merge(T entity)
entity -
IllegalArgumentException - if instance is not an entity or is a removed entity
TransactionRequiredException - if invoked on a container-managed entity manager of type
PersistenceContextType.TRANSACTION and there is no transactionvoid remove(Object entity)
entity -
IllegalArgumentException - if the instance is not an entity or is a detached entity
TransactionRequiredException - if invoked on a container-managed entity manager of type
PersistenceContextType.TRANSACTION and there is no transaction
<T> T find(Class<T> entityClass,
Object primaryKey)
entityClass - primaryKey -
IllegalArgumentException - 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,
Map<String,Object> properties)
entityClass - primaryKey - properties - standard and vendor-specific properties and hints
IllegalArgumentException - 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)
entityClass - primaryKey - lockMode -
IllegalArgumentException - 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 null
TransactionRequiredException - if there is no transaction and a lock mode other than NONE is specified
OptimisticLockException - if the optimistic version check fails
PessimisticLockException - if pessimistic locking fails and the transaction is rolled back
LockTimeoutException - if pessimistic locking fails and only the statement is rolled back
PersistenceException - if an unsupported lock call is made
<T> T find(Class<T> entityClass,
Object primaryKey,
LockModeType lockMode,
Map<String,Object> properties)
entityClass - primaryKey - lockMode - properties - standard and vendor-specific properties and hints
IllegalArgumentException - 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 null
TransactionRequiredException - if there is no transaction and a lock mode other than NONE is specified
OptimisticLockException - if the optimistic version check fails
PessimisticLockException - if pessimistic locking fails and the transaction is rolled back
LockTimeoutException - if pessimistic locking fails and only the statement is rolled back
PersistenceException - if an unsupported lock call is made
<T> T getReference(Class<T> entityClass,
Object primaryKey)
entityClass - primaryKey -
IllegalArgumentException - 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 null
EntityNotFoundException - if the entity state cannot be accessedvoid flush()
TransactionRequiredException - if there is no transaction
PersistenceException - if the flush failsvoid setFlushMode(FlushModeType flushMode)
flushMode - FlushModeType getFlushMode()
void lock(Object entity,
LockModeType lockMode)
entity - lockMode -
IllegalArgumentException - if the instance is not an entity or is a detached entity
TransactionRequiredException - if there is no transaction
EntityNotFoundException - if the entity does not exist in the database when pessimistic locking is performed
OptimisticLockException - if the optimistic version check fails
PessimisticLockException - if pessimistic locking fails and the transaction is rolled back
LockTimeoutException - if pessimistic locking fails and only the statement is rolled back
PersistenceException - if an unsupported lock call is made
void lock(Object entity,
LockModeType lockMode,
Map<String,Object> properties)
entity - lockMode - properties - standard and vendor-specific properties and hints
IllegalArgumentException - if the instance is not an entity or is a detached entity
TransactionRequiredException - if there is no transaction
EntityNotFoundException - if the entity does not exist in the database when pessimistic locking is performed
OptimisticLockException - if the optimistic version check fails
PessimisticLockException - if pessimistic locking fails and the transaction is rolled back
LockTimeoutException - if pessimistic locking fails and only the statement is rolled back
PersistenceException - if an unsupported lock call is madevoid refresh(Object entity)
entity -
IllegalArgumentException - if the instance is not an entity or the entity is not managed
TransactionRequiredException - if invoked on a container-managed entity manager of type
PersistenceContextType.TRANSACTION and there is no transaction
EntityNotFoundException - if the entity no longer exists in the database
void refresh(Object entity,
Map<String,Object> properties)
entity - properties - standard and vendor-specific properties and hints
IllegalArgumentException - if the instance is not an entity or the entity is not managed
TransactionRequiredException - if invoked on a container-managed entity manager of type
PersistenceContextType.TRANSACTION and there is no transaction
EntityNotFoundException - if the entity no longer exists in the database
void refresh(Object entity,
LockModeType lockMode)
entity - lockMode -
IllegalArgumentException - if the instance is not an entity or the entity is not managed
TransactionRequiredException - if there is no transaction and if invoked on a container-managed EntityManager
instance with PersistenceContextType.TRANSACTION or with a lock mode other than NONE
EntityNotFoundException - if the entity no longer exists in the database
PessimisticLockException - if pessimistic locking fails and the transaction is rolled back
LockTimeoutException - if pessimistic locking fails and only the statement is rolled back
PersistenceException - if an unsupported lock call is made
void refresh(Object entity,
LockModeType lockMode,
Map<String,Object> properties)
entity - lockMode - properties - standard and vendor-specific properties and hints
IllegalArgumentException - if the instance is not an entity or the entity is not managed
TransactionRequiredException - if there is no transaction and if invoked on a container-managed EntityManager
instance with PersistenceContextType.TRANSACTION or with a lock mode other than NONE
EntityNotFoundException - if the entity no longer exists in the database
PessimisticLockException - if pessimistic locking fails and the transaction is rolled back
LockTimeoutException - if pessimistic locking fails and only the statement is rolled back
PersistenceException - if an unsupported lock call is madevoid clear()
void detach(Object entity)
entity -
IllegalArgumentException - if the instance is not an entityboolean contains(Object entity)
entity -
IllegalArgumentException - if not an entityLockModeType getLockMode(Object entity)
entity -
TransactionRequiredException - if there is no transaction
IllegalArgumentException - if the instance is not a managed entity and a transaction is active
void setProperty(String propertyName,
Object value)
propertyName - name of property or hintvalue -
IllegalArgumentException - if the second argument is not valid for the implementationMap<String,Object> getProperties()
Query createQuery(String qlString)
qlString - a Java Persistence query string
IllegalArgumentException - if the query string is found to be invalid<T> TypedQuery<T> createQuery(CriteriaQuery<T> criteriaQuery)
criteriaQuery - a criteria query object
IllegalArgumentException - if the criteria query is found to be invalid
<T> TypedQuery<T> createQuery(String qlString,
Class<T> resultClass)
qlString - a Java Persistence query stringresultClass - the type of the query result
IllegalArgumentException - if the query string is found to be invalid or if the query result is found to not be
assignable to the specified typeQuery createNamedQuery(String name)
name - the name of a query defined in metadata
IllegalArgumentException - 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)
name - the name of a query defined in metadataresultClass - the type of the query result
IllegalArgumentException - 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 string
Query 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
void joinTransaction()
TransactionRequiredException - if there is no transaction<T> T unwrap(Class<T> cls)
cls - 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 callObject getDelegate()
void close()
IllegalStateException - if the entity manager is container-managedboolean isOpen()
EntityTransaction getTransaction()
IllegalStateException - if invoked on a JTA entity managerEntityManagerFactory getEntityManagerFactory()
IllegalStateException - if the entity manager has been closedCriteriaBuilder getCriteriaBuilder()
IllegalStateException - if the entity manager has been closedMetamodel getMetamodel()
IllegalStateException - if the entity manager has been closed
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||