| javax.persistence.EntityManager
EntityManager | public interface EntityManager (Code) | | 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.
since: Java Persistence 1.0 |
Method Summary | |
public void | clear() Clear the persistence context, causing all managed
entities to become detached. | public void | close() Close an application-managed EntityManager. | 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 the Java Persistence query language or in 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 qlString) Create an instance of Query for executing a
Java Persistence query language statement. | public T | find(Class<T> entityClass, Object primaryKey) Find by primary key. | public void | flush() Synchronize the persistence context to the
underlying database. | public Object | getDelegate() Return the underlying provider object for the EntityManager,
if available. | public FlushModeType | getFlushMode() Get the flush mode that applies to all objects contained
in the persistence context. | public T | getReference(Class<T> entityClass, Object primaryKey) Get an instance, whose state may be lazily fetched.
If the requested instance does not exist in the database,
throws
EntityNotFoundException when the instance state is
first accessed. | public EntityTransaction | getTransaction() Returns the resource-level transaction object. | public boolean | isOpen() Determine whether the EntityManager is open. | public void | joinTransaction() Indicate to the EntityManager that a JTA transaction is
active. | 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. |
clear | public void clear()(Code) | | 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.
throws: IllegalStateException - if this EntityManager has been closed. |
close | public void close()(Code) | | 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.
throws: IllegalStateException - if the EntityManageris container-managed or has been already closed.. |
contains | public boolean contains(Object entity)(Code) | | Check if the instance belongs to the current persistence
context.
Parameters: entity - true if the instance belongs to the current persistence context. throws: IllegalStateException - if this EntityManager has been closed. throws: IllegalArgumentException - if not an entity |
createNamedQuery | public Query createNamedQuery(String name)(Code) | | Create an instance of Query for executing a
named query (in the Java Persistence query language or in native SQL).
Parameters: name - the name of a query defined in metadata the new query instance throws: IllegalStateException - if this EntityManager has been closed. throws: IllegalArgumentException - if a query has not beendefined with the given name |
createNativeQuery | public Query createNativeQuery(String sqlString)(Code) | | Create an instance of Query for executing
a native SQL statement, e.g., for update or delete.
Parameters: sqlString - a native SQL query string the new query instance throws: IllegalStateException - if this EntityManager has been closed. |
createNativeQuery | public Query createNativeQuery(String sqlString, Class resultClass)(Code) | | Create an instance of Query for executing
a native SQL query.
Parameters: sqlString - a native SQL query string Parameters: resultClass - the class of the resulting instance(s) the new query instance throws: IllegalStateException - if this EntityManager has been closed. |
createNativeQuery | public Query createNativeQuery(String sqlString, String resultSetMapping)(Code) | | Create an instance of Query for executing
a native SQL query.
Parameters: sqlString - a native SQL query string Parameters: resultSetMapping - the name of the result set mapping the new query instance throws: IllegalStateException - if this EntityManager has been closed. |
createQuery | public Query createQuery(String qlString)(Code) | | Create an instance of Query for executing a
Java Persistence query language statement.
Parameters: qlString - a Java Persistence query language query string the new query instance throws: IllegalStateException - if this EntityManager has been closed. throws: IllegalArgumentException - if query string is not valid |
find | public T find(Class<T> entityClass, Object primaryKey)(Code) | | Find by primary key.
Parameters: entityClass - Parameters: primaryKey - the found entity instance or nullif the entity does not exist throws: IllegalStateException - if this EntityManager has been closed. throws: IllegalArgumentException - if the first argument doesnot denote an entity type or the secondargument is not a valid type for thatentity's primary key |
getDelegate | public Object getDelegate()(Code) | | Return the underlying provider object for the EntityManager,
if available. The result of this method is implementation
specific.
throws: IllegalStateException - if this EntityManager has been closed. |
getFlushMode | public FlushModeType getFlushMode()(Code) | | Get the flush mode that applies to all objects contained
in the persistence context.
flush mode throws: IllegalStateException - if this EntityManager has been closed. |
getReference | public T getReference(Class<T> entityClass, Object primaryKey)(Code) | | Get an instance, whose state may be lazily fetched.
If the requested instance does not exist in the database,
throws
EntityNotFoundException when the instance state is
first accessed. (The persistence provider runtime is permitted to throw
EntityNotFoundException when
EntityManager.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.
Parameters: entityClass - Parameters: primaryKey - the found entity instance throws: IllegalStateException - if this EntityManager has been closed. throws: IllegalArgumentException - if the first argument doesnot denote an entity type or the secondargument is not a valid type for thatentity's primary key throws: EntityNotFoundException - if the entity statecannot be accessed |
getTransaction | public EntityTransaction getTransaction()(Code) | | Returns the resource-level transaction object.
The EntityTransaction instance may be used serially to
begin and commit multiple transactions.
EntityTransaction instance throws: IllegalStateException - if invoked on a JTAEntityManager. |
isOpen | public boolean isOpen()(Code) | | Determine whether the EntityManager is open.
true until the EntityManager has been closed. |
joinTransaction | public void joinTransaction()(Code) | | 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.
throws: IllegalStateException - if this EntityManager has been closed. throws: TransactionRequiredException - if there isno transaction. |
merge | public T merge(T entity)(Code) | | Merge the state of the given entity into the
current persistence context.
Parameters: entity - the instance that the state was merged to throws: IllegalStateException - if this EntityManager has been closed. throws: IllegalArgumentException - if instance is not anentity or is a removed entity throws: TransactionRequiredException - if invoked on acontainer-managed entity manager of typePersistenceContextType.TRANSACTION and there isno transaction. |
persist | public void persist(Object entity)(Code) | | Make an entity instance managed and persistent.
Parameters: entity - throws: EntityExistsException - if the entity already exists.(The EntityExistsException may be thrown when the persistoperation is invoked, or the EntityExistsException oranother PersistenceException may be thrown at flush or committime.) throws: IllegalStateException - if this EntityManager has been closed. throws: IllegalArgumentException - if not an entity throws: TransactionRequiredException - if invoked on acontainer-managed entity manager of typePersistenceContextType.TRANSACTION and there isno transaction. |
refresh | public void refresh(Object entity)(Code) | | Refresh the state of the instance from the database,
overwriting changes made to the entity, if any.
Parameters: entity - throws: IllegalStateException - if this EntityManager has been closed. throws: IllegalArgumentException - if not an entityor entity is not managed throws: TransactionRequiredException - if invoked on acontainer-managed entity manager of typePersistenceContextType.TRANSACTION and there isno transaction. throws: EntityNotFoundException - if the entity no longerexists in the database. |
setFlushMode | public void setFlushMode(FlushModeType flushMode)(Code) | | Set the flush mode that applies to all objects contained
in the persistence context.
Parameters: flushMode - throws: IllegalStateException - if this EntityManager has been closed. |
|
|