|
Préférences
Moteurs de recherche
|
|||||||||||||||||||||||||||||||||||||||||||||||||
JavaTM Platform, Enterprise Edition, v 5.0
javax.persistence
|
Method Summary | ||
---|---|---|
void |
clear()
Clear the persistence context, causing all managed entities to become detached. |
|
void |
close()
Close an application-managed EntityManager. |
|
boolean |
contains(Object entity)
Check if the instance belongs 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(String qlString)
Create an instance of Query for executing a Java Persistence query language statement. |
|
|
find(Class<T> entityClass,
Object primaryKey)
Find by primary key. |
|
void |
flush()
Synchronize the persistence context to the underlying database. |
|
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. |
|
|
getReference(Class<T> entityClass,
Object primaryKey)
Get an instance, whose state may be lazily fetched. |
|
EntityTransaction |
getTransaction()
Returns 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)
Set the lock mode for an entity object contained in the persistence context. |
|
|
merge(T entity)
Merge the state of the given entity into the current persistence context. |
|
void |
persist(Object entity)
Make an entity 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 |
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. |
Method Detail |
---|
void persist(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 flush or commit
time.)
IllegalStateException
- if this EntityManager has been closed.
IllegalArgumentException
- if 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
-
IllegalStateException
- if this EntityManager has been closed.
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
-
IllegalStateException
- if this EntityManager has been closed.
IllegalArgumentException
- if not an entity
or if 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
-
IllegalStateException
- if this EntityManager has been closed.
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(Class<T> entityClass, Object primaryKey)
EntityNotFoundException
when the instance state is
first accessed. (The persistence provider runtime is permitted to throw
EntityNotFoundException
when getReference(java.lang.Class, java.lang.Object)
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.
entityClass
- primaryKey
-
IllegalStateException
- if this EntityManager has been closed.
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
EntityNotFoundException
- if the entity state
cannot be accessedvoid flush()
IllegalStateException
- if this EntityManager has been closed.
TransactionRequiredException
- if there is
no transaction
PersistenceException
- if the flush failsvoid setFlushMode(FlushModeType flushMode)
flushMode
-
IllegalStateException
- if this EntityManager has been closed.FlushModeType getFlushMode()
IllegalStateException
- if this EntityManager has been closed.void lock(Object entity, LockModeType lockMode)
entity
- lockMode
-
IllegalStateException
- if this EntityManager has been closed.
PersistenceException
- if an unsupported lock call
is made
IllegalArgumentException
- if the instance is not
an entity or is a detached entity
TransactionRequiredException
- if there is no
transactionvoid refresh(Object entity)
entity
-
IllegalStateException
- if this EntityManager has been closed.
IllegalArgumentException
- if not an entity
or 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 clear()
IllegalStateException
- if this EntityManager has been closed.boolean contains(Object entity)
entity
-
true
if the instance belongs to
the current persistence context.
IllegalStateException
- if this EntityManager has been closed.
IllegalArgumentException
- if not an entityQuery createQuery(String qlString)
qlString
- a Java Persistence query language query string
IllegalStateException
- if this EntityManager has been closed.
IllegalArgumentException
- if query string is not validQuery createNamedQuery(String name)
name
- the name of a query defined in metadata
IllegalStateException
- if this EntityManager has been closed.
IllegalArgumentException
- if a query has not been
defined with the given nameQuery createNativeQuery(String sqlString)
sqlString
- a native SQL query string
IllegalStateException
- if this EntityManager has been closed.Query createNativeQuery(String sqlString, Class resultClass)
sqlString
- a native SQL query stringresultClass
- the class of the resulting instance(s)
IllegalStateException
- if this EntityManager has been closed.Query createNativeQuery(String sqlString, String resultSetMapping)
sqlString
- a native SQL query stringresultSetMapping
- the name of the result set mapping
IllegalStateException
- if this EntityManager has been closed.void joinTransaction()
IllegalStateException
- if this EntityManager has been closed.
TransactionRequiredException
- if there is
no transaction.Object getDelegate()
IllegalStateException
- if this EntityManager has been closed.void close()
IllegalStateException
- if the EntityManager
is container-managed or has been already closed..boolean isOpen()
EntityTransaction getTransaction()
IllegalStateException
- if invoked on a JTA
EntityManager.