javax.persistence
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 EntityManager.
|
boolean |
contains(java.lang.Object entity)
Check if the instance belongs to the current persistence
context.
|
Query |
createNamedQuery(java.lang.String name)
Create an instance of Query for executing a
named query (in EJB QL or native SQL).
|
Query |
createNativeQuery(java.lang.String sqlString)
Create an instance of Query for executing
a native SQL statement, e.g., for update or delete.
|
Query |
createNativeQuery(java.lang.String sqlString,
java.lang.Class resultClass)
Create an instance of Query for executing
a native SQL query.
|
Query |
createNativeQuery(java.lang.String sqlString,
java.lang.String resultSetMapping)
Create an instance of Query for executing
a native SQL query.
|
Query |
createQuery(java.lang.String ejbqlString)
Create an instance of Query for executing an
EJB QL statement.
|
<T> T |
find(java.lang.Class<T> entityClass,
java.lang.Object primaryKey)
Find by primary key.
|
void |
flush()
Synchronize the persistence context to the
underlying database.
|
java.lang.Object |
getDelegate()
Return the underlying provider object for the EntityManager, if available.
|
FlushModeType |
getFlushMode()
Get the flush mode that applies to all objects contained
in the persistence context.
|
<T> T |
getReference(java.lang.Class<T> entityClass,
java.lang.Object primaryKey)
Get an instance, whose state may be lazily fetched.
|
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(java.lang.Object entity,
LockModeType lockMode)
Set the lock mode for an entity object contained
in the persistence context.
|
<T> T |
merge(T entity)
Merge the state of the given entity into the
current persistence context.
|
void |
persist(java.lang.Object entity)
Make an entity instance managed and persistent.
|
void |
refresh(java.lang.Object entity)
Refresh the state of the instance from the database,
overwriting changes made to the entity, if any.
|
void |
remove(java.lang.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 persist(java.lang.Object entity)
entity
- EntityExistsException
- 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 commit
time.)java.lang.IllegalStateException
- if this EntityManager has been closed.java.lang.IllegalArgumentException
- if not an entityTransactionRequiredException
- if invoked on a
container-managed entity manager of type
PersistenceContextType.TRANSACTION and there is
no transaction.<T> T merge(T entity)
entity
- java.lang.IllegalStateException
- if this EntityManager has been closedjava.lang.IllegalArgumentException
- if instance is not an
entity or is a removed entityTransactionRequiredException
- if invoked on a
container-managed entity manager of type
PersistenceContextType.TRANSACTION and there is
no transaction.void remove(java.lang.Object entity)
entity
- java.lang.IllegalStateException
- if this EntityManager has been closedjava.lang.IllegalArgumentException
- if not an entity
or if a detached entityTransactionRequiredException
- if invoked on a
container-managed entity manager of type
PersistenceContextType.TRANSACTION and there is
no transaction.<T> T find(java.lang.Class<T> entityClass, java.lang.Object primaryKey)
entityClass
- primaryKey
- java.lang.IllegalStateException
- if this EntityManager has been closedjava.lang.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<T> T getReference(java.lang.Class<T> entityClass, java.lang.Object primaryKey)
entityClass
- primaryKey
- java.lang.IllegalStateException
- if this EntityManager has been closedjava.lang.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 keyEntityNotFoundException
- if the entity state
cannot be accessedvoid flush()
java.lang.IllegalStateException
- if this EntityManager has been closedTransactionRequiredException
- if there is
no transactionPersistenceException
- if the flush failsvoid setFlushMode(FlushModeType flushMode)
flushMode
- java.lang.IllegalStateException
- if this EntityManager has been closedFlushModeType getFlushMode()
java.lang.IllegalStateException
- if this EntityManager has been closedvoid lock(java.lang.Object entity, LockModeType lockMode)
entity
- lockMode
- java.lang.IllegalStateException
- if this EntityManager has been closedPersistenceException
- if an unsupported lock call
is madejava.lang.IllegalArgumentException
- if the instance is not
an entity or is a detached entityTransactionRequiredException
- if there is no
transactionvoid refresh(java.lang.Object entity)
entity
- java.lang.IllegalStateException
- if this EntityManager has been closedjava.lang.IllegalArgumentException
- if not an entity
or entity is not managedTransactionRequiredException
- 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 databasevoid clear()
java.lang.IllegalStateException
- if this EntityManager has been closedboolean contains(java.lang.Object entity)
entity
- true
if the instance belongs to the current persistence context.java.lang.IllegalStateException
- if this EntityManager has been closedjava.lang.IllegalArgumentException
- if not an entityQuery createQuery(java.lang.String ejbqlString)
ejbqlString
- an EJB QL query stringjava.lang.IllegalStateException
- if this EntityManager has been closedjava.lang.IllegalArgumentException
- if query string is not validQuery createNamedQuery(java.lang.String name)
name
- the name of a query defined in metadatajava.lang.IllegalStateException
- if this EntityManager has been closedjava.lang.IllegalArgumentException
- if a query has not been
defined with the given nameQuery createNativeQuery(java.lang.String sqlString)
sqlString
- a native SQL query stringjava.lang.IllegalStateException
- if this EntityManager has been closedQuery createNativeQuery(java.lang.String sqlString, java.lang.Class resultClass)
sqlString
- a native SQL query stringresultClass
- the class of the resulting instance(s)java.lang.IllegalStateException
- if this EntityManager has been closedQuery createNativeQuery(java.lang.String sqlString, java.lang.String resultSetMapping)
sqlString
- a native SQL query stringresultSetMapping
- the name of the result set mappingjava.lang.IllegalStateException
- if this EntityManager has been closedvoid joinTransaction()
java.lang.IllegalStateException
- if this EntityManager has been closedTransactionRequiredException
- if there is
no transaction.java.lang.Object getDelegate()
java.lang.IllegalStateException
- if this EntityManager has been closedvoid close()
java.lang.IllegalStateException
- if the EntityManager is container-managed or has been already closedboolean isOpen()
EntityTransaction getTransaction()
java.lang.IllegalStateException
- if invoked on a JTA
EntityManager.