|
||||||||||
| 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()
Return the underlying provider object for the EntityManager, if available. |
|
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). |
|
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. |
|
Query |
createQuery(CriteriaQuery criteriaQuery)
Create an instance of Query for executing a criteria query. |
|
Query |
createQuery(String qlString)
Create an instance of Query 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. |
|
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 associated values that are in effect for the entity manager. |
|
QueryBuilder |
getQueryBuilder()
Return an instance of QueryBuilder for the creation of Criteria API Query objects. |
|
|
getReference(Class<T> entityClass,
Object primaryKey)
Get an instance, whose state may be lazily fetched. |
|
Set<String> |
getSupportedProperties()
Get the names of the properties that are supported for use with the entity manager. |
|
EntityTransaction |
getTransaction()
Return the resource-level transaction object. |
|
boolean |
isOpen()
Determine whether the EntityManager is open. |
|
void |
joinTransaction()
Indicate to the EntityManager 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. |
|
|
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 transaction.void 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
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 set
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 set
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
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
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
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 - value -
IllegalArgumentException - if the second argument is not
valid for the implementationMap<String,Object> getProperties()
Set<String> getSupportedProperties()
Query createQuery(String qlString)
qlString - a Java Persistence query string
IllegalArgumentException - if the query string is found
to be invalidQuery createQuery(CriteriaQuery criteriaQuery)
criteriaQuery - a Criteria API query definition object
IllegalArgumentException - if the query definition is
found to be invalidQuery 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 invalidQuery 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 call.Object getDelegate()
void close()
IllegalStateException - if the EntityManager
is container-managed.boolean isOpen()
EntityTransaction getTransaction()
IllegalStateException - if invoked on a JTA
EntityManager.EntityManagerFactory getEntityManagerFactory()
IllegalStateException - if the entity manager has
been closed.QueryBuilder getQueryBuilder()
IllegalStateException - if the entity manager has
been closed.Metamodel 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 | |||||||||