public class JtaEntityManager extends java.lang.Object implements EntityManager, java.io.Serializable
Modifier and Type | Class and Description |
---|---|
static class |
JtaEntityManager.Timer |
Constructor and Description |
---|
JtaEntityManager(JtaEntityManagerRegistry registry,
EntityManagerFactory entityManagerFactory,
java.util.Map properties,
java.lang.String unitName,
java.lang.String synchronizationType) |
JtaEntityManager(java.lang.String unitName,
JtaEntityManagerRegistry registry,
EntityManagerFactory entityManagerFactory,
java.util.Map properties,
boolean extended,
java.lang.String synchronizationType) |
Modifier and Type | Method and Description |
---|---|
void |
clear()
Clear the persistence context, causing all managed
entities to become detached.
|
void |
close()
close throws an IllegalStateException if the em is container managed otherwise (emf.newEM()) it is delegated to the user
|
boolean |
contains(java.lang.Object entity)
Check if the instance is a managed entity instance belonging
to the current persistence context.
|
<T> EntityGraph<T> |
createEntityGraph(java.lang.Class<T> rootType)
Return a mutable EntityGraph that can be used to dynamically create an
EntityGraph.
|
EntityGraph<?> |
createEntityGraph(java.lang.String graphName)
Return a mutable copy of the named EntityGraph.
|
Query |
createNamedQuery(java.lang.String name)
Create an instance of
Query for executing a named query
(in the Java Persistence query language or in native SQL). |
<T> TypedQuery<T> |
createNamedQuery(java.lang.String name,
java.lang.Class<T> resultClass)
Create an instance of
TypedQuery for executing a
Java Persistence query language named query. |
StoredProcedureQuery |
createNamedStoredProcedureQuery(java.lang.String name)
Create an instance of
StoredProcedureQuery for executing a
stored procedure in the database. |
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(CriteriaDelete deleteQuery)
Create an instance of
Query for executing a criteria
delete query. |
<T> TypedQuery<T> |
createQuery(CriteriaQuery<T> criteriaQuery)
Create an instance of
TypedQuery for executing a
criteria query. |
Query |
createQuery(CriteriaUpdate updateQuery)
Create an instance of
Query for executing a criteria
update query. |
Query |
createQuery(java.lang.String qlString)
Create an instance of
Query for executing a
Java Persistence query language statement. |
<T> TypedQuery<T> |
createQuery(java.lang.String qlString,
java.lang.Class<T> resultClass)
Create an instance of
TypedQuery for executing a
Java Persistence query language statement. |
StoredProcedureQuery |
createStoredProcedureQuery(java.lang.String procedureName)
Create an instance of
StoredProcedureQuery for executing a
stored procedure in the database. |
StoredProcedureQuery |
createStoredProcedureQuery(java.lang.String procedureName,
java.lang.Class... resultClasses)
Create an instance of
StoredProcedureQuery for executing a
stored procedure in the database. |
StoredProcedureQuery |
createStoredProcedureQuery(java.lang.String procedureName,
java.lang.String... resultSetMappings)
Create an instance of
StoredProcedureQuery for executing a
stored procedure in the database. |
void |
detach(java.lang.Object entity)
Remove the given entity from the persistence context, causing
a managed entity to become detached.
|
<T> T |
find(java.lang.Class<T> entityClass,
java.lang.Object primaryKey)
Find by primary key.
|
<T> T |
find(java.lang.Class<T> entityClass,
java.lang.Object primaryKey,
LockModeType lockMode)
Find by primary key and lock.
|
<T> T |
find(java.lang.Class<T> entityClass,
java.lang.Object primaryKey,
LockModeType lockMode,
java.util.Map<java.lang.String,java.lang.Object> properties)
Find by primary key and lock, using the specified properties.
|
<T> T |
find(java.lang.Class<T> entityClass,
java.lang.Object primaryKey,
java.util.Map<java.lang.String,java.lang.Object> properties)
Find by primary key, using the specified properties.
|
void |
flush()
Synchronize the persistence context to the
underlying database.
|
CriteriaBuilder |
getCriteriaBuilder()
Return an instance of
CriteriaBuilder for the creation of
CriteriaQuery objects. |
EntityManager |
getDelegate()
Return the underlying provider object for the
EntityManager ,
if available. |
EntityGraph<?> |
getEntityGraph(java.lang.String graphName)
Return a named EntityGraph.
|
<T> java.util.List<EntityGraph<? super T>> |
getEntityGraphs(java.lang.Class<T> entityClass)
Return all named EntityGraphs that have been defined for the provided
class type.
|
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(java.lang.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. |
java.util.Map<java.lang.String,java.lang.Object> |
getProperties()
Get the properties and hints and associated values that are in effect
for the entity manager.
|
<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
EntityTransaction object. |
boolean |
isJoinedToTransaction()
Determine whether the entity manager is joined to the
current transaction.
|
static boolean |
isJPA21(EntityManagerFactory entityManagerFactory) |
boolean |
isOpen()
Determine whether the entity manager is open.
|
void |
joinTransaction()
Indicate to the entity manager that a JTA transaction is
active and join the persistence context to it.
|
void |
lock(java.lang.Object entity,
LockModeType lockMode)
Lock an entity instance that is contained in the persistence
context with the specified lock mode type.
|
void |
lock(java.lang.Object entity,
LockModeType lockMode,
java.util.Map<java.lang.String,java.lang.Object> properties)
Lock an entity instance that is contained in the persistence
context with the specified lock mode type and with specified
properties.
|
<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 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 |
refresh(java.lang.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(java.lang.Object entity,
LockModeType lockMode,
java.util.Map<java.lang.String,java.lang.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(java.lang.Object entity,
java.util.Map<java.lang.String,java.lang.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(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 |
setProperty(java.lang.String name,
java.lang.Object value)
Set an entity manager property or hint.
|
<T> T |
unwrap(java.lang.Class<T> cls)
Return an object of the specified type to allow access to the
provider-specific API.
|
protected java.lang.Object |
writeReplace() |
public JtaEntityManager(JtaEntityManagerRegistry registry, EntityManagerFactory entityManagerFactory, java.util.Map properties, java.lang.String unitName, java.lang.String synchronizationType)
public JtaEntityManager(java.lang.String unitName, JtaEntityManagerRegistry registry, EntityManagerFactory entityManagerFactory, java.util.Map properties, boolean extended, java.lang.String synchronizationType)
public static boolean isJPA21(EntityManagerFactory entityManagerFactory)
public EntityManager getDelegate()
EntityManager
EntityManager
,
if available. The result of this method is implementation
specific.
The unwrap
method is to be preferred for new applications.
getDelegate
in interface EntityManager
public void persist(java.lang.Object entity)
EntityManager
persist
in interface EntityManager
entity
- entity instancepublic <T> T merge(T entity)
EntityManager
merge
in interface EntityManager
entity
- entity instancepublic void remove(java.lang.Object entity)
EntityManager
remove
in interface EntityManager
entity
- entity instancepublic <T> T find(java.lang.Class<T> entityClass, java.lang.Object primaryKey)
EntityManager
find
in interface EntityManager
entityClass
- entity classprimaryKey
- primary keypublic <T> T getReference(java.lang.Class<T> entityClass, java.lang.Object primaryKey)
EntityManager
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.getReference
in interface EntityManager
entityClass
- entity classprimaryKey
- primary keypublic void flush()
EntityManager
flush
in interface EntityManager
public void setFlushMode(FlushModeType flushMode)
EntityManager
setFlushMode
in interface EntityManager
flushMode
- flush modepublic FlushModeType getFlushMode()
EntityManager
getFlushMode
in interface EntityManager
public void lock(java.lang.Object entity, LockModeType lockMode)
EntityManager
If a pessimistic lock mode type is specified and the entity
contains a version attribute, the persistence provider must
also perform optimistic version checks when obtaining the
database lock. If these checks fail, the
OptimisticLockException
will be thrown.
If the lock mode type is pessimistic and the entity instance is found but cannot be locked:
PessimisticLockException
will be thrown if the database
locking failure causes transaction-level rollback
LockTimeoutException
will be thrown if the database
locking failure causes only statement-level rollback
lock
in interface EntityManager
entity
- entity instancelockMode
- lock modepublic void refresh(java.lang.Object entity)
EntityManager
refresh
in interface EntityManager
entity
- entity instancepublic void clear()
EntityManager
clear
in interface EntityManager
public boolean contains(java.lang.Object entity)
EntityManager
contains
in interface EntityManager
entity
- entity instancepublic Query createQuery(java.lang.String qlString)
EntityManager
Query
for executing a
Java Persistence query language statement.createQuery
in interface EntityManager
qlString
- a Java Persistence query stringpublic Query createNamedQuery(java.lang.String name)
EntityManager
Query
for executing a named query
(in the Java Persistence query language or in native SQL).createNamedQuery
in interface EntityManager
name
- the name of a query defined in metadatapublic Query createNativeQuery(java.lang.String sqlString)
EntityManager
Query
for executing
a native SQL statement, e.g., for update or delete.
If the query is not an update or delete query, query
execution will result in each row of the SQL result
being returned as a result of type Object[] (or a result
of type Object if there is only one column in the select
list.) Column values are returned in the order of their
appearance in the select list and default JDBC type
mappings are applied.createNativeQuery
in interface EntityManager
sqlString
- a native SQL query stringpublic Query createNativeQuery(java.lang.String sqlString, java.lang.Class resultClass)
EntityManager
Query
for executing
a native SQL query.createNativeQuery
in interface EntityManager
sqlString
- a native SQL query stringresultClass
- the class of the resulting instance(s)public Query createNativeQuery(java.lang.String sqlString, java.lang.String resultSetMapping)
EntityManager
Query
for executing
a native SQL query.createNativeQuery
in interface EntityManager
sqlString
- a native SQL query stringresultSetMapping
- the name of the result set mappingpublic void joinTransaction()
EntityManager
This method should be called on a JTA application
managed entity manager that was created outside the scope
of the active transaction or on an entity manager of type
SynchronizationType.UNSYNCHRONIZED
to associate
it with the current JTA transaction.
joinTransaction
in interface EntityManager
public void close()
close
in interface EntityManager
public boolean isOpen()
EntityManager
isOpen
in interface EntityManager
public EntityTransaction getTransaction()
EntityManager
EntityTransaction
object.
The EntityTransaction
instance may be used serially to
begin and commit multiple transactions.getTransaction
in interface EntityManager
public <T> TypedQuery<T> createNamedQuery(java.lang.String name, java.lang.Class<T> resultClass)
EntityManager
TypedQuery
for executing a
Java Persistence query language named query.
The select list of the query must contain only a single
item, which must be assignable to the type specified by
the resultClass
argument.createNamedQuery
in interface EntityManager
name
- the name of a query defined in metadataresultClass
- the type of the query resultpublic <T> TypedQuery<T> createQuery(CriteriaQuery<T> criteriaQuery)
EntityManager
TypedQuery
for executing a
criteria query.createQuery
in interface EntityManager
criteriaQuery
- a criteria query objectpublic <T> TypedQuery<T> createQuery(java.lang.String qlString, java.lang.Class<T> resultClass)
EntityManager
TypedQuery
for executing a
Java Persistence query language statement.
The select list of the query must contain only a single
item, which must be assignable to the type specified by
the resultClass
argument.createQuery
in interface EntityManager
qlString
- a Java Persistence query stringresultClass
- the type of the query resultpublic void detach(java.lang.Object entity)
EntityManager
detach
in interface EntityManager
entity
- entity instancepublic <T> T find(java.lang.Class<T> entityClass, java.lang.Object primaryKey, java.util.Map<java.lang.String,java.lang.Object> properties)
EntityManager
find
in interface EntityManager
entityClass
- entity classprimaryKey
- primary keyproperties
- standard and vendor-specific properties
and hintspublic <T> T find(java.lang.Class<T> entityClass, java.lang.Object primaryKey, LockModeType lockMode)
EntityManager
If the entity is found within the persistence context and the
lock mode type is pessimistic and the entity has a version
attribute, the persistence provider must perform optimistic
version checks when obtaining the database lock. If these
checks fail, the OptimisticLockException
will be thrown.
If the lock mode type is pessimistic and the entity instance is found but cannot be locked:
PessimisticLockException
will be thrown if the database
locking failure causes transaction-level rollback
LockTimeoutException
will be thrown if the database
locking failure causes only statement-level rollback
find
in interface EntityManager
entityClass
- entity classprimaryKey
- primary keylockMode
- lock modepublic <T> T find(java.lang.Class<T> entityClass, java.lang.Object primaryKey, LockModeType lockMode, java.util.Map<java.lang.String,java.lang.Object> properties)
EntityManager
If the entity is found
within the persistence context and the lock mode type
is pessimistic and the entity has a version attribute, the
persistence provider must perform optimistic version checks
when obtaining the database lock. If these checks fail,
the OptimisticLockException
will be thrown.
If the lock mode type is pessimistic and the entity instance is found but cannot be locked:
PessimisticLockException
will be thrown if the database
locking failure causes transaction-level rollback
LockTimeoutException
will be thrown if the database
locking failure causes only statement-level rollback
If a vendor-specific property or hint is not recognized, it is silently ignored.
Portable applications should not rely on the standard timeout hint. Depending on the database in use and the locking mechanisms used by the provider, the hint may or may not be observed.
find
in interface EntityManager
entityClass
- entity classprimaryKey
- primary keylockMode
- lock modeproperties
- standard and vendor-specific properties
and hintspublic EntityManagerFactory getEntityManagerFactory()
EntityManager
getEntityManagerFactory
in interface EntityManager
public LockModeType getLockMode(java.lang.Object entity)
EntityManager
getLockMode
in interface EntityManager
entity
- entity instancepublic Metamodel getMetamodel()
EntityManager
Metamodel
interface for access to the
metamodel of the persistence unit.getMetamodel
in interface EntityManager
public java.util.Map<java.lang.String,java.lang.Object> getProperties()
EntityManager
getProperties
in interface EntityManager
public CriteriaBuilder getCriteriaBuilder()
EntityManager
CriteriaBuilder
for the creation of
CriteriaQuery
objects.getCriteriaBuilder
in interface EntityManager
public void lock(java.lang.Object entity, LockModeType lockMode, java.util.Map<java.lang.String,java.lang.Object> properties)
EntityManager
If a pessimistic lock mode type is specified and the entity
contains a version attribute, the persistence provider must
also perform optimistic version checks when obtaining the
database lock. If these checks fail, the
OptimisticLockException
will be thrown.
If the lock mode type is pessimistic and the entity instance is found but cannot be locked:
PessimisticLockException
will be thrown if the database
locking failure causes transaction-level rollback
LockTimeoutException
will be thrown if the database
locking failure causes only statement-level rollback
If a vendor-specific property or hint is not recognized, it is silently ignored.
Portable applications should not rely on the standard timeout hint. Depending on the database in use and the locking mechanisms used by the provider, the hint may or may not be observed.
lock
in interface EntityManager
entity
- entity instancelockMode
- lock modeproperties
- standard and vendor-specific properties
and hintspublic void refresh(java.lang.Object entity, java.util.Map<java.lang.String,java.lang.Object> properties)
EntityManager
If a vendor-specific property or hint is not recognized, it is silently ignored.
refresh
in interface EntityManager
entity
- entity instanceproperties
- standard and vendor-specific properties
and hintspublic void refresh(java.lang.Object entity, LockModeType lockMode)
EntityManager
If the lock mode type is pessimistic and the entity instance is found but cannot be locked:
PessimisticLockException
will be thrown if the database
locking failure causes transaction-level rollback
LockTimeoutException
will be thrown if the
database locking failure causes only statement-level
rollback.
refresh
in interface EntityManager
entity
- entity instancelockMode
- lock modepublic void refresh(java.lang.Object entity, LockModeType lockMode, java.util.Map<java.lang.String,java.lang.Object> properties)
EntityManager
If the lock mode type is pessimistic and the entity instance is found but cannot be locked:
PessimisticLockException
will be thrown if the database
locking failure causes transaction-level rollback
LockTimeoutException
will be thrown if the database
locking failure causes only statement-level rollback
If a vendor-specific property or hint is not recognized, it is silently ignored.
Portable applications should not rely on the standard timeout hint. Depending on the database in use and the locking mechanisms used by the provider, the hint may or may not be observed.
refresh
in interface EntityManager
entity
- entity instancelockMode
- lock modeproperties
- standard and vendor-specific properties
and hintspublic void setProperty(java.lang.String name, java.lang.Object value)
EntityManager
setProperty
in interface EntityManager
name
- name of property or hintvalue
- value for property or hintpublic <T> T unwrap(java.lang.Class<T> cls)
EntityManager
EntityManager
implementation does not support the specified class, the
PersistenceException
is thrown.unwrap
in interface EntityManager
cls
- the class of the object to be returned. This is
normally either the underlying EntityManager
implementation
class or an interface that it implements.protected java.lang.Object writeReplace() throws java.io.ObjectStreamException
java.io.ObjectStreamException
public StoredProcedureQuery createNamedStoredProcedureQuery(java.lang.String name)
EntityManager
StoredProcedureQuery
for executing a
stored procedure in the database.
Parameters must be registered before the stored procedure can be executed.
If the stored procedure returns one or more result sets, any result set will be returned as a list of type Object[].
createNamedStoredProcedureQuery
in interface EntityManager
name
- name assigned to the stored procedure query
in metadatapublic StoredProcedureQuery createStoredProcedureQuery(java.lang.String procedureName)
EntityManager
StoredProcedureQuery
for executing a
stored procedure in the database.
Parameters must be registered before the stored procedure can be executed.
If the stored procedure returns one or more result sets, any result set will be returned as a list of type Object[].
createStoredProcedureQuery
in interface EntityManager
procedureName
- name of the stored procedure in the
databasepublic StoredProcedureQuery createStoredProcedureQuery(java.lang.String procedureName, java.lang.Class... resultClasses)
EntityManager
StoredProcedureQuery
for executing a
stored procedure in the database.
Parameters must be registered before the stored procedure can be executed.
The resultClass
arguments must be specified in the order in
which the result sets will be returned by the stored procedure
invocation.
createStoredProcedureQuery
in interface EntityManager
procedureName
- name of the stored procedure in the
databaseresultClasses
- classes to which the result sets
produced by the stored procedure are to
be mappedpublic StoredProcedureQuery createStoredProcedureQuery(java.lang.String procedureName, java.lang.String... resultSetMappings)
EntityManager
StoredProcedureQuery
for executing a
stored procedure in the database.
Parameters must be registered before the stored procedure can be executed.
The resultSetMapping
arguments must be specified in the order
in which the result sets will be returned by the stored
procedure invocation.
createStoredProcedureQuery
in interface EntityManager
procedureName
- name of the stored procedure in the
databaseresultSetMappings
- the names of the result set mappings
to be used in mapping result sets
returned by the stored procedurepublic Query createQuery(CriteriaUpdate updateQuery)
EntityManager
Query
for executing a criteria
update query.createQuery
in interface EntityManager
updateQuery
- a criteria update query objectpublic Query createQuery(CriteriaDelete deleteQuery)
EntityManager
Query
for executing a criteria
delete query.createQuery
in interface EntityManager
deleteQuery
- a criteria delete query objectpublic <T> EntityGraph<T> createEntityGraph(java.lang.Class<T> rootType)
EntityManager
createEntityGraph
in interface EntityManager
rootType
- class of entity graphpublic EntityGraph<?> createEntityGraph(java.lang.String graphName)
EntityManager
createEntityGraph
in interface EntityManager
graphName
- name of an entity graphpublic EntityGraph<?> getEntityGraph(java.lang.String graphName)
EntityManager
getEntityGraph
in interface EntityManager
graphName
- name of an existing entity graphpublic <T> java.util.List<EntityGraph<? super T>> getEntityGraphs(java.lang.Class<T> entityClass)
EntityManager
getEntityGraphs
in interface EntityManager
entityClass
- entity classpublic boolean isJoinedToTransaction()
EntityManager
isJoinedToTransaction
in interface EntityManager