]
Interface used to interact with the persistence context.
An EntityManager instance is associated with a persistence context. A persistence context is a set of
entity instances in which for any persistent entity identity there is a unique entity instance.
Within the persistence context, the entity instances and their lifecycle are managed. This interface
defines the methods that are used to interact with the persistence context. The EntityManager API is
used to create and remove persistent entity instances, to find entities by their primary key, and to
query over entities.
The set of entities that can be managed by a given EntityManager instance is defined by a persistence unit.
A persistence unit defines the set of all classes that are related or grouped by the application, and
which must be colocated in their mapping to a single database.
| Method from javax.persistence.EntityManager Detail: |
public void clear()
Clear the persistence context, causing all managed
entities to become detached. Changes made to entities that
have not been flushed to the database will not be
persisted. |
public void close()
Close an application-managed EntityManager.
After the close method has been invoked, all methods
on the EntityManager instance and any Query objects obtained
from it will throw the IllegalStateException except
for getTransaction and isOpen (which will return false).
If this method is called when the EntityManager is
associated with an active transaction, the persistence
context remains managed until the transaction completes. |
public boolean contains(Object entity)
Check if the instance belongs to the current persistence
context. |
public Query createNamedQuery(String name)
Create an instance of Query for executing a
named query (in EJB QL or native SQL). |
public Query createNativeQuery(String sqlString)
Create an instance of Query for executing
a native SQL statement, e.g., for update or delete. |
public Query createNativeQuery(String sqlString,
Class resultClass)
Create an instance of Query for executing
a native SQL query. |
public Query createNativeQuery(String sqlString,
String resultSetMapping)
Create an instance of Query for executing
a native SQL query. |
public Query createQuery(String ejbqlString)
Create an instance of Query for executing an
EJB QL statement. |
public T find(Class entityClass,
Object primaryKey)
|
public void flush()
Synchronize the persistence context to the
underlying database. |
public Object getDelegate()
Return the underlying provider object for the EntityManager, if available.
The result of this method is implementation specific |
public FlushModeType getFlushMode()
Get the flush mode that applies to all objects contained
in the persistence context. |
public T getReference(Class entityClass,
Object primaryKey)
Get an instance, whose state may be lazily fetched.
If the requested instance does not exist in the database,
the EntityNotFoundException 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. |
public EntityTransaction getTransaction()
Return the resource-level transaction object.
The EntityTransaction instance may be used serially to
begin and commit multiple transactions. |
public boolean isOpen()
Determine whether the EntityManager is open. |
public void joinTransaction()
Indicate to the EntityManager that a JTA transaction is
active. This method should be called on a JTA application
managed EntityManager that was created outside the scope
of the active transaction to associate it with the current
JTA transaction. |
public void lock(Object entity,
LockModeType lockMode)
Set the lock mode for an entity object contained
in the persistence context. |
public T merge(T entity)
Merge the state of the given entity into the
current persistence context. |
public void persist(Object entity)
Make an entity instance managed and persistent. |
public void refresh(Object entity)
Refresh the state of the instance from the database,
overwriting changes made to the entity, if any. |
public void remove(Object entity)
Remove the entity instance. |
public void setFlushMode(FlushModeType flushMode)
Set the flush mode that applies to all objects contained
in the persistence context. |