Class EntityManagerImpl
- All Implemented Interfaces:
EntityManager
,AutoCloseable
,JpaEntityManager
Purpose: Contains the implementation of the EntityManager.
Description: This class provides the implementation for the combined EclipseLink and JPA EntityManager class.
Responsibilities: It is responsible for tracking transaction state and the objects within that transaction.
- Since:
- TopLink Essentials - JPA 1.0
- See Also:
-
Nested Class Summary
-
Field Summary
Modifier and TypeFieldDescriptionprotected boolean
Join existing transaction property, allows reading through write connection.protected boolean
Property to avoid writing to the cache on commit (merge)protected boolean
Property to avoid resuming unit of work if going to be closed on commit anyway.protected UnitOfWork.CommitOrderType
Allow updates to be ordered by id to avoid possible deadlocks.protected boolean
protected Map
<String, ConnectionPolicy> In case of composite persistence unit this map is used instead of connectionPolicy attribute.protected ConnectionPolicy
Connection policy used to create ClientSession, allows using a different pool/connection/exclusive connections.protected AbstractSession
References the DatabaseSession that this deployment is using.protected RepeatableWriteUnitOfWork
Stores the UnitOfWork representing the persistence context.protected EntityManagerFactoryDelegate
References to the parent factory that has created this entity manager.protected String
The FlashClearCache mode to be used.protected FlushModeType
Flush mode property, allows flush before query to be avoided.protected boolean
Store if this entity manager has been closed.protected WeakHashMap
<QueryImpl, QueryImpl> Keep a list of openQueries that are executed in this entity manager.protected boolean
Property to avoid discover new objects in unit of work if application always uses persist.Local properties passed from createEntityManager.protected AbstractSession
Stores a session used for read-only queries.protected ReferenceMode
Reference mode property, allows weak unit of work references to allow garbage collection during a transaction.protected boolean
Determine if does-exist should be performed on persist.protected SynchronizationType
Tracks if this EntityManager should automatically associate with the transaction or not -
Constructor Summary
ConstructorDescriptionEntityManagerImpl
(String sessionName) Constructor returns an EntityManager assigned to the a particular DatabaseSession.EntityManagerImpl
(EntityManagerFactoryDelegate factory, Map properties, SynchronizationType syncType) Constructor called from the EntityManagerFactory to create an EntityManagerEntityManagerImpl
(AbstractSession databaseSession, SynchronizationType syncType) Constructor called from the EntityManagerFactory to create an EntityManagerEntityManagerImpl
(AbstractSession databaseSession, Map properties, SynchronizationType syncType) Constructor called from the EntityManagerFactory to create an EntityManager -
Method Summary
Modifier and TypeMethodDescriptionvoid
addOpenQuery
(QueryImpl query) Queries that leave the connection and are executed against this entity manager will be added here.protected Object
checkForTransaction
(boolean validateExistence) Return the current, joined transaction object.void
clear()
Clear the persistence context, causing all managed entities to become detached.void
close()
Closes this EntityManager.protected void
Close any open queries executed against this entity manager.0boolean
Check if the instance belongs to the current persistence context.protected boolean
contains
(Object entity, UnitOfWork uow) Check if the instance belongs to the current persistence context.copy
(Object entityOrEntities, AttributeGroup group) This method will return copy the passed entity using the passed AttributeGroup.protected void
createConnectionPolicies
(Map mapOfProperties) Create connection policy using properties.protected void
Create connection policy using properties.protected static ConnectionPolicy
createConnectionPolicy
(ServerSession serverSession, Map properties) Create connection policy using properties.createDescriptorNamedQuery
(String queryName, Class<?> descriptorClass) This method will create a query object that wraps a EclipseLink Named Query.createDescriptorNamedQuery
(String queryName, Class<?> descriptorClass, List argumentTypes) This method will create a query object that wraps a EclipseLink Named Query.<T> EntityGraph
<T> createEntityGraph
(Class<T> rootType) createEntityGraph
(String graphName) createNamedQuery
(String name) Create an instance of Query for executing a named query (in EJBQL or native SQL).<T> TypedQuery
<T> createNamedQuery
(String name, Class<T> resultClass) Create an instance of TypedQuery for executing a named query (in the Java Persistence query language or in native SQL).Create an instance of StoredProcedureQuery for executing a stored procedure in the database.createNativeQuery
(String sqlString) Create an instance of Query for executing a native SQL query.createNativeQuery
(String sqlString, Class resultType) This method is used to create a query using SQL.createNativeQuery
(String sqlString, String resultSetMapping) Create an instance of Query for executing a native SQL query.createQuery
(CriteriaDelete deleteQuery) <T> TypedQuery
<T> createQuery
(CriteriaQuery<T> criteriaQuery) createQuery
(CriteriaUpdate updateQuery) createQuery
(String jpqlString) Create an instance of Query for executing an JPQL query.<T> TypedQuery
<T> createQuery
(String qlString, Class<T> resultClass) Create an instance of TypedQuery for executing a Java Persistence query language statement.createQuery
(Expression expression, Class<?> resultType) This method is used to create a query using a EclipseLink Expression and the return type.createQuery
(Call call) This method is used to create a query using a EclipseLink Call.createQuery
(Call call, Class<?> entityClass) This method is used to create a query using a EclipseLink Call.createQuery
(DatabaseQuery databaseQuery) This method is used to create a query using a EclipseLink DatabaseQuery.createQueryByExample
(Object exampleObject) This method is used to create a query using a EclipseLink by example.protected DatabaseQuery
createQueryInternal
(Expression expression, Class<?> resultType) This method is used to create a query using a EclipseLink Expression and the return type.createStoredProcedureQuery
(String procedureName) Create an instance ofStoredProcedureQuery
for executing a stored procedure in the database.createStoredProcedureQuery
(String procedureName, Class... resultClasses) Create an instance ofStoredProcedureQuery
for executing a stored procedure in the database.createStoredProcedureQuery
(String procedureName, String... resultSetMappings) Create an instance ofStoredProcedureQuery
for executing a stored procedure in the database.void
Remove the given entity from the persistence context, causing a managed entity to become detached.protected void
<T> T
Find by primary key.<T> T
find
(Class<T> entityClass, Object primaryKey, LockModeType lockMode) Find by primary key and lock.<T> T
Find by primary key and lock.<T> T
Find by primary key, using the specified properties.Find by primary key.protected Object
findInternal
(ClassDescriptor descriptor, AbstractSession session, Object id, LockModeType lockMode, Map<String, Object> properties) Find by primary key.void
flush()
Synchronize the persistence context with the underlying database.Return the underlying database sessionThis method returns the current session to the requestor.This method returns the current session to the requestor.Return an instance of CriteriaBuilder for the creation of Criteria API Query objects.Return the underlying database sessionReturn the underlying provider object for the EntityManager, if available.getEntityGraph
(String graphName) <T> List
<EntityGraph<? super T>> getEntityGraphs
(Class<T> entityClass) Return the entity manager factory for the entity manager.Get the flush mode that applies to all objects contained in the persistence context.getLockMode
(Object entity) getMemberDatabaseSession
(Class<?> cls) Return the member DatabaseSessionImpl that maps cls in session broker.getMemberServerSession
(Class<?> cls) Return the member ServerSession that maps cls in session broker.getMemberSessionName
(Class<?> cls) Return the name of member session that maps cls.Return an instance of Metamodel interface for access to the metamodel of the persistence unit.Return the weak reference to the open queries.Return the weak reference to the open queries.Get the properties and associated values that are in effect for the entity manager.protected String
Get the local EntityManager property from the properties Map.protected static String
getPropertiesHandlerProperty
(String name, String value) Verifies and (if required) translates the value.getProperty
(String name) The method search for user defined property passed in from EntityManager, if it is not found then search for it from EntityManagerFactory properties.getQueryHints
(Object entity, EntityManagerImpl.OperationType operation) Before any find or refresh operation, gather any persistence unit properties that should be applied to the query.protected ReadObjectQuery
getReadObjectQuery
(Class<?> referenceClass, Object primaryKey, Map properties) Build a selection query for the primary key values.protected ReadObjectQuery
getReadObjectQuery
(Object entity, Map properties) Build a selection query for the given entity.protected ReadObjectQuery
getReadObjectQuery
(Map properties) Build a selection query using the given properties.Return a read-only session (client session) for read-only operations.<T> T
getReference
(Class<T> entityClass, Object primaryKey) Get an instance, whose state may be lazily fetched.Return the underlying server session, throws ClassCastException if it's not a ServerSession.This method will return a Session outside of a transaction and null within a transaction.Return the underlying session broker, throws ClassCastException if it's not a SessionBroker.Get the names of the properties that are supported for use with the entity manager.INTERNAL: Tracks if this EntityManager should automatically associate with the transaction or notReturns the resource-level transaction object.This method will return the active UnitOfWorkboolean
This method is used in contains to check if we already have a persistence context.protected void
initialize
(Map properties) Initialize the state after construction.boolean
isBroker()
Indicates whether the underlying session is a session broker.boolean
Internal method.boolean
boolean
isOpen()
Indicates whether or not this entity manager and its entity manager factory are open.protected static boolean
isPropertyToBeAdded
(String value) Property value is to be added if it's non null and not an empty string.protected static boolean
isPropertyToBeAdded
(DataSource ds, String dsName) protected static boolean
isPropertyToBeRemoved
(String value) Property value of an empty string indicates that the existing property should be removed.protected static Boolean
isPropertyValueToBeUpdated
(String oldValue, String newValue) void
Indicate to the EntityManager that a JTA transaction is active.void
load
(Object entityOrEntities, AttributeGroup group) This method will load the passed entity or collection of entities using the passed AttributeGroup.void
lock
(Object entity, LockModeType lockMode) Set the lock mode for an entity object contained in the persistence context.void
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, using the unqualified class name as the entity name.protected Object
mergeInternal
(Object entity) Merge the state of the given entity into the current persistence context, using the unqualified class name as the entity name.void
If in a transaction this method will check for existence and register the object if it is new.protected void
Process the local EntityManager properties only.static void
processUnfetchedAttribute
(FetchGroupTracker entity, String attributeName) INTERNAL: Load/fetch the unfetched object.static void
processUnfetchedAttributeForSet
(FetchGroupTracker entity, String attributeName) INTERNAL: Load/fetch the unfetched object.void
Refresh the state of the instance from the database.void
refresh
(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 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 the state of the instance from the database, using the specified properties, and overwriting changes made to the entity, if any.void
Remove the instance.void
Internal method called by EntityTransactionImpl class in case of transaction rollback.void
setAbstractSession
(AbstractSession session) INTERNAL: Set the underlying database sessionprotected void
void
setFlushMode
(FlushModeType flushMode) Set the flush mode that applies to all objects contained in the persistence context.protected void
void
setProperties
(Map properties) Use this method to set properties into existing EntityManager that are normally passed to createEntityManager method.void
setProperty
(String propertyName, Object value) protected void
Internal method.boolean
Indicate the early transaction should be forced to start.boolean
<T> T
Return an object of the specified type to allow access to the provider-specific API.void
void
used to save having to constantly use a try/catch to call setRollbackOnly
-
Field Details
-
isOpen
protected boolean isOpenStore if this entity manager has been closed. -
extendedPersistenceContext
Stores the UnitOfWork representing the persistence context. -
readOnlySession
Stores a session used for read-only queries. -
databaseSession
References the DatabaseSession that this deployment is using. -
factory
References to the parent factory that has created this entity manager. Ensures that the factory is not garbage collected. -
beginEarlyTransaction
protected boolean beginEarlyTransactionJoin existing transaction property, allows reading through write connection. -
properties
Local properties passed from createEntityManager. -
flushMode
Flush mode property, allows flush before query to be avoided. -
referenceMode
Reference mode property, allows weak unit of work references to allow garbage collection during a transaction. -
connectionPolicy
Connection policy used to create ClientSession, allows using a different pool/connection/exclusive connections. Not used in SessionBroker case (composite persistence unit case). -
connectionPolicies
In case of composite persistence unit this map is used instead of connectionPolicy attribute. Member sessions' ConnectionPolicies keyed by sessions' names (composite members' persistence unit names). Used only in SessionBroker case (composite persistence unit case): in that case guaranteed to be always non null. -
openQueriesMap
Keep a list of openQueries that are executed in this entity manager. -
closeOnCommit
protected boolean closeOnCommitProperty to avoid resuming unit of work if going to be closed on commit anyway. -
persistOnCommit
protected boolean persistOnCommitProperty to avoid discover new objects in unit of work if application always uses persist. -
cacheStoreBypass
protected boolean cacheStoreBypassProperty to avoid writing to the cache on commit (merge) -
flushClearCache
The FlashClearCache mode to be used. Relevant only in case call to flush method followed by call to clear method.- See Also:
-
shouldValidateExistence
protected boolean shouldValidateExistenceDetermine if does-exist should be performed on persist. -
commitOrder
Allow updates to be ordered by id to avoid possible deadlocks. -
commitWithoutPersistRules
protected boolean commitWithoutPersistRules -
syncType
Tracks if this EntityManager should automatically associate with the transaction or not
-
-
Constructor Details
-
EntityManagerImpl
Constructor returns an EntityManager assigned to the a particular DatabaseSession.- Parameters:
sessionName
- the DatabaseSession name that should be used. This constructor can potentially throw EclipseLink exceptions regarding the existence, or errors with the specified session.
-
EntityManagerImpl
Constructor called from the EntityManagerFactory to create an EntityManager- Parameters:
databaseSession
- the databaseSession assigned to this deployment.
-
EntityManagerImpl
public EntityManagerImpl(AbstractSession databaseSession, Map properties, SynchronizationType syncType) Constructor called from the EntityManagerFactory to create an EntityManager- Parameters:
databaseSession
- the databaseSession assigned to this deployment. Note: The properties argument is provided to allow properties to be passed into this EntityManager, but there are currently no such properties implemented
-
EntityManagerImpl
public EntityManagerImpl(EntityManagerFactoryDelegate factory, Map properties, SynchronizationType syncType) Constructor called from the EntityManagerFactory to create an EntityManager- Parameters:
factory
- the EntityMangerFactoryImpl that created this entity manager. Note: The properties argument is provided to allow properties to be passed into this EntityManager, but there are currently no such properties implemented
-
-
Method Details
-
getOpenQueriesMap
Return the weak reference to the open queries. -
getOpenQueriesSet
Return the weak reference to the open queries. -
addOpenQuery
Queries that leave the connection and are executed against this entity manager will be added here. On rollback or commit any left over open queries should be closed. -
initialize
Initialize the state after construction. -
clear
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.- Specified by:
clear
in interfaceEntityManager
-
removeExtendedPersistenceContext
public void removeExtendedPersistenceContext()Internal method called by EntityTransactionImpl class in case of transaction rollback. The caller is responsible for releasing extendedPersistenceContext and it's parent. -
persist
If in a transaction this method will check for existence and register the object if it is new. The instance of the entity provided will become managed.- Specified by:
persist
in interfaceEntityManager
- Throws:
IllegalArgumentException
- if the given Object is not an entity.
-
merge
public <T> T merge(T entity) Merge the state of the given entity into the current persistence context, using the unqualified class name as the entity name.- Specified by:
merge
in interfaceEntityManager
- Returns:
- the instance that the state was merged to
-
mergeInternal
Merge the state of the given entity into the current persistence context, using the unqualified class name as the entity name.- Returns:
- the instance that the state was merged to
- Throws:
IllegalArgumentException
- if given Object is not an entity or is a removed entity
-
remove
Remove the instance.- Specified by:
remove
in interfaceEntityManager
- Throws:
IllegalArgumentException
- if Object passed in is not an entity
-
find
Find by primary key.- Specified by:
find
in interfaceEntityManager
- Parameters:
entityClass
- - the entity class to find.primaryKey
- - the entity primary key value, or primary key class, or a List of primary key values.- Returns:
- the found entity instance or null if the entity does not exist
- Throws:
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.
-
find
Find by primary key, using the specified properties. Search for an entity of the specified class and primary key. If the entity instance is contained in the persistence context it is returned from there. If a vendor-specific property or hint is not recognized, it is silently ignored.- Specified by:
find
in interfaceEntityManager
- Parameters:
properties
- standard and vendor-specific properties- Returns:
- the found entity instance or null if the entity does not exist
- Throws:
IllegalArgumentException
- if the first argument does not denote an entity type or the second argument is is not a valid type for that entity's primary key or is null- Since:
- Java Persistence API 2.0
-
find
Find by primary key and lock. Search for an entity of the specified class and primary key and lock it with respect to the specified lock type. If the entity instance is contained in the persistence context it is returned from there. 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: - the PessimisticLockException will be thrown if the database locking failure causes transaction-level rollback. - the LockTimeoutException will be thrown if the database locking failure causes only statement-level rollback- Specified by:
find
in interfaceEntityManager
- Returns:
- the found entity instance or null if the entity does not exist
- Throws:
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 or is nullTransactionRequiredException
- if there is no transaction and a lock mode other than NONE is setOptimisticLockException
- if the optimistic version check failsPessimisticLockException
- if pessimistic locking fails and the transaction is rolled backLockTimeoutException
- if pessimistic locking fails and only the statement is rolled backPersistenceException
- if an unsupported lock call is made
-
find
public <T> T find(Class<T> entityClass, Object primaryKey, LockModeType lockMode, Map<String, Object> properties) Find by primary key and lock. Search for an entity of the specified class and primary key and lock it with respect to the specified lock type. If the entity instance is contained in the persistence context it is returned from there. 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: - the PessimisticLockException will be thrown if the database locking failure causes transaction-level rollback. - the 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.- Specified by:
find
in interfaceEntityManager
- Parameters:
properties
- standard and vendor-specific properties and hints- Returns:
- the found entity instance or null if the entity does not exist
- Throws:
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 or is nullTransactionRequiredException
- if there is no transaction and a lock mode other than NONE is setOptimisticLockException
- if the optimistic version check failsPessimisticLockException
- if pessimistic locking fails and the transaction is rolled backLockTimeoutException
- if pessimistic locking fails and only the statement is rolled backPersistenceException
- if an unsupported lock call is made
-
find
Find by primary key.- Parameters:
entityName
- - the entity class to find.primaryKey
- - the entity primary key value, or primary key class, or a List of primary key values.- Returns:
- the found entity instance or null, if the entity does not exist.
- Throws:
IllegalArgumentException
- if the first argument does not indicate an entity or if the second argument is not a valid type for that entity's primaryKey.
-
findInternal
protected Object findInternal(ClassDescriptor descriptor, AbstractSession session, Object id, LockModeType lockMode, Map<String, Object> properties) Find by primary key.- Parameters:
descriptor
- - the entity class to find.id
- - the entity primary key value, or primary key class, or a List of primary key values.- Returns:
- the found entity instance or null, if the entity does not exist.
- Throws:
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.
-
flush
public void flush()Synchronize the persistence context with the underlying database.- Specified by:
flush
in interfaceEntityManager
-
detectTransactionWrapper
protected void detectTransactionWrapper() -
refresh
Refresh the state of the instance from the database.- Specified by:
refresh
in interfaceEntityManager
- Parameters:
entity
- instance registered in the current persistence context.
-
refresh
Refresh the state of the instance from the database, using the specified properties, and overwriting changes made to the entity, if any. If a vendor-specific property or hint is not recognized, it is silently ignored.- Specified by:
refresh
in interfaceEntityManager
- Parameters:
properties
- standard and vendor-specific properties- Throws:
IllegalArgumentException
- if the instance is not an entity or the 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 database- Since:
- Java Persistence API 2.0
-
refresh
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. If the lock mode type is pessimistic and the entity instance is found but cannot be locked: - the PessimisticLockException will be thrown if the database locking failure causes transaction-level rollback. - the LockTimeoutException will be thrown if the database locking failure causes only statement-level rollback.- Specified by:
refresh
in interfaceEntityManager
- Throws:
IllegalArgumentException
- if the instance is not an entity or the entity is not managedTransactionRequiredException
- if there is no transactionEntityNotFoundException
- if the entity no longer exists in the databasePessimisticLockException
- if pessimistic locking fails and the transaction is rolled backLockTimeoutException
- if pessimistic locking fails and only the statement is rolled backPersistenceException
- if an unsupported lock call is made
-
refresh
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. If the lock mode type is pessimistic and the entity instance is found but cannot be locked: - the PessimisticLockException will be thrown if the database locking failure causes transaction-level rollback. - the 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.- Specified by:
refresh
in interfaceEntityManager
- Parameters:
properties
- standard and vendor-specific properties and hints- Throws:
IllegalArgumentException
- if the instance is not an entity or the entity is not managedTransactionRequiredException
- if there is no transactionEntityNotFoundException
- if the entity no longer exists in the databasePessimisticLockException
- if pessimistic locking fails and the transaction is rolled backLockTimeoutException
- if pessimistic locking fails and only the statement is rolled backPersistenceException
- if an unsupported lock call is made
-
contains
Check if the instance belongs to the current persistence context.- Specified by:
contains
in interfaceEntityManager
- Throws:
IllegalArgumentException
- if given Object is not an entity
-
contains
Check if the instance belongs to the current persistence context. -
createDescriptorNamedQuery
Description copied from interface:JpaEntityManager
This method will create a query object that wraps a EclipseLink Named Query.- Specified by:
createDescriptorNamedQuery
in interfaceJpaEntityManager
-
createDescriptorNamedQuery
public Query createDescriptorNamedQuery(String queryName, Class<?> descriptorClass, List argumentTypes) Description copied from interface:JpaEntityManager
This method will create a query object that wraps a EclipseLink Named Query.- Specified by:
createDescriptorNamedQuery
in interfaceJpaEntityManager
-
createNamedQuery
Create an instance of Query for executing a named query (in EJBQL or native SQL).- Specified by:
createNamedQuery
in interfaceEntityManager
- Parameters:
name
- the name of a query defined in metadata- Returns:
- the new query instance
-
createNamedQuery
Create an instance of TypedQuery for executing a named query (in the Java Persistence query language or in native SQL).- Specified by:
createNamedQuery
in interfaceEntityManager
- Parameters:
name
- the name of a query defined in metadataresultClass
- the type of the query result- Returns:
- the new query instance
- Throws:
IllegalArgumentException
- if a query has not been defined with the given name or if the query string is found to be invalid
-
createNamedStoredProcedureQuery
Create an instance of StoredProcedureQuery for executing a stored procedure in the database.- Specified by:
createNamedStoredProcedureQuery
in interfaceEntityManager
- Parameters:
name
- name assigned to the stored procedure query in metadata- Returns:
- the new stored procedure query instance
- Throws:
IllegalArgumentException
- if a query has not been defined with the given name
-
createNativeQuery
Create an instance of Query for executing a native SQL query.- Specified by:
createNativeQuery
in interfaceEntityManager
- Parameters:
sqlString
- a native SQL query string- Returns:
- the new query instance
-
createNativeQuery
This method is used to create a query using SQL. The class, must be the expected return type.- Specified by:
createNativeQuery
in interfaceEntityManager
-
createNativeQuery
Create an instance of Query for executing a native SQL query.- Specified by:
createNativeQuery
in interfaceEntityManager
- Parameters:
sqlString
- a native SQL query stringresultSetMapping
- the name of the result set mapping- Returns:
- the new query instance
- Throws:
IllegalArgumentException
- if query string is not valid
-
getActiveSession
This method returns the current session to the requestor. The current session will be a the active UnitOfWork within a transaction and will be a 'scrap' UnitOfWork outside of a transaction. The caller is concerned about the results then the getSession() or getUnitOfWork() API should be called.- Specified by:
getActiveSession
in interfaceJpaEntityManager
-
getActiveSessionIfExists
This method returns the current session to the requestor. The current session will be a the active UnitOfWork within a transaction and will be a 'scrap' UnitOfWork outside of a transaction. The caller is concerned about the results then the getSession() or getUnitOfWork() API should be called. -
getDelegate
Return the underlying provider object for the EntityManager, if available. The result of this method is implementation specific.- Specified by:
getDelegate
in interfaceEntityManager
-
getFlushMode
Get the flush mode that applies to all objects contained in the persistence context.- Specified by:
getFlushMode
in interfaceEntityManager
- Returns:
- flushMode
-
getUnitOfWork
This method will return the active UnitOfWork- Specified by:
getUnitOfWork
in interfaceJpaEntityManager
-
getSession
This method will return a Session outside of a transaction and null within a transaction.- Specified by:
getSession
in interfaceJpaEntityManager
-
getTransaction
Returns the resource-level transaction object. The EntityTransaction instance may be used serially to begin and commit multiple transactions.- Specified by:
getTransaction
in interfaceEntityManager
- Returns:
- EntityTransaction instance
- Throws:
IllegalStateException
- if invoked on a JTA EntityManager.
-
getProperty
The method search for user defined property passed in from EntityManager, if it is not found then search for it from EntityManagerFactory properties. -
getReadObjectQuery
protected ReadObjectQuery getReadObjectQuery(Class<?> referenceClass, Object primaryKey, Map properties) Build a selection query for the primary key values. -
getReadObjectQuery
Build a selection query using the given properties. -
getReadObjectQuery
Build a selection query for the given entity. -
getReference
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 container is permitted to throw EntityNotFoundException when get 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.- Specified by:
getReference
in interfaceEntityManager
- Returns:
- the found entity instance.
- Throws:
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 accessed.
-
getReadOnlySession
Return a read-only session (client session) for read-only operations. -
getDatabaseSession
Return the underlying database session- Specified by:
getDatabaseSession
in interfaceJpaEntityManager
-
getAbstractSession
Return the underlying database session- Specified by:
getAbstractSession
in interfaceJpaEntityManager
-
setAbstractSession
INTERNAL: Set the underlying database session -
getServerSession
Return the underlying server session, throws ClassCastException if it's not a ServerSession.- Specified by:
getServerSession
in interfaceJpaEntityManager
-
getSessionBroker
Return the underlying session broker, throws ClassCastException if it's not a SessionBroker.- Specified by:
getSessionBroker
in interfaceJpaEntityManager
-
getMemberDatabaseSession
Return the member DatabaseSessionImpl that maps cls in session broker. Return null if either not a session broker or cls is not mapped. Session broker implement composite persistence unit.- Specified by:
getMemberDatabaseSession
in interfaceJpaEntityManager
-
getMemberServerSession
Return the member ServerSession that maps cls in session broker. Return null if either not a session broker or cls is not mapped. Session broker implement composite persistence unit.- Specified by:
getMemberServerSession
in interfaceJpaEntityManager
-
getMemberSessionName
Return the name of member session that maps cls. Return null if either not a session broker or cls is not mapped. Session broker implement composite persistence unit.- Specified by:
getMemberSessionName
in interfaceJpaEntityManager
-
createQuery
This method is used to create a query using a EclipseLink Expression and the return type.- Specified by:
createQuery
in interfaceJpaEntityManager
-
createQuery
This method is used to create a query using a EclipseLink DatabaseQuery.- Specified by:
createQuery
in interfaceJpaEntityManager
-
createQuery
- Specified by:
createQuery
in interfaceEntityManager
- Since:
- Java Persistence 2.0
- See Also:
-
createQueryByExample
This method is used to create a query using a EclipseLink by example.- Specified by:
createQueryByExample
in interfaceJpaEntityManager
-
createQuery
This method is used to create a query using a EclipseLink Call.- Specified by:
createQuery
in interfaceJpaEntityManager
-
createQuery
This method is used to create a query using a EclipseLink Call.- Specified by:
createQuery
in interfaceJpaEntityManager
-
createQuery
Create an instance of Query for executing an JPQL query.- Specified by:
createQuery
in interfaceEntityManager
- Parameters:
jpqlString
- an JPQL query string- Returns:
- the new query instance
-
createQuery
Create an instance of TypedQuery for executing a Java Persistence query language statement.- Specified by:
createQuery
in interfaceEntityManager
- Parameters:
qlString
- a Java Persistence query stringresultClass
- the type of the query result- Returns:
- the new query instance
- Throws:
IllegalArgumentException
- if the query string is found to be invalid
-
createQueryInternal
This method is used to create a query using a EclipseLink Expression and the return type. -
createStoredProcedureQuery
Create an instance ofStoredProcedureQuery
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[].
- Specified by:
createStoredProcedureQuery
in interfaceEntityManager
- Parameters:
procedureName
- name of the stored procedure in the database- Returns:
- the new stored procedure query instance
- Throws:
IllegalArgumentException
- if a stored procedure of the given name does not exist (or the query execution will fail)- Since:
- EclipseLink 2.5/Java Persistence 2.1
-
createStoredProcedureQuery
public StoredProcedureQuery createStoredProcedureQuery(String procedureName, Class... resultClasses) Create an instance ofStoredProcedureQuery
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.- Specified by:
createStoredProcedureQuery
in interfaceEntityManager
- Parameters:
procedureName
- name of the stored procedure in the databaseresultClasses
- classes to which the result sets produced by the stored procedure are to be mapped- Returns:
- the new stored procedure query instance
- Throws:
IllegalArgumentException
- if a stored procedure of the given name does not exist (or the query execution will fail)- Since:
- EclipseLink 2.5/Java Persistence 2.1
-
createStoredProcedureQuery
public StoredProcedureQuery createStoredProcedureQuery(String procedureName, String... resultSetMappings) Create an instance ofStoredProcedureQuery
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.- Specified by:
createStoredProcedureQuery
in interfaceEntityManager
- Parameters:
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 procedure- Returns:
- the new stored procedure query instance
- Throws:
IllegalArgumentException
- if a stored procedure or result set mapping of the given name does not exist (or the query execution will fail)- Since:
- EclipseLink 2.5/Java Persistence 2.1
-
close
public void close()Closes this EntityManager.
After invoking this method, all methods on the instance will throw an
IllegalStateException
except forisOpen
, which will returnfalse
.This should be called when a method is finished with the EntityManager in a bean-managed transaction environment or when executed outside a container. Closing of the EntityManager is handled by the container when using container-managed transactions.
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceEntityManager
-
closeOpenQueries
protected void closeOpenQueries()Close any open queries executed against this entity manager.0 -
isFlushModeAUTO
public boolean isFlushModeAUTO()Internal method. Indicates whether flushMode is AUTO.- Returns:
- boolean
-
isOpen
public boolean isOpen()Indicates whether or not this entity manager and its entity manager factory are open. Returnstrue
until a call toclose()
is made.- Specified by:
isOpen
in interfaceEntityManager
-
lock
Set the lock mode for an entity object contained in the persistence context.- Specified by:
lock
in interfaceEntityManager
- Throws:
PersistenceException
- if an unsupported lock call is madeIllegalArgumentException
- if the instance is not an entity or is a detached entityTransactionRequiredException
- if there is no transaction
-
lock
Set the lock mode for an entity object contained in the persistence context.- Specified by:
lock
in interfaceEntityManager
- Throws:
PersistenceException
- if an unsupported lock call is madeIllegalArgumentException
- if the instance is not an entity or is a detached entityTransactionRequiredException
- if there is no transaction
-
verifyOpen
public void verifyOpen() -
verifyOpenWithSetRollbackOnly
public void verifyOpenWithSetRollbackOnly()used to save having to constantly use a try/catch to call setRollbackOnly -
getActivePersistenceContext
-
setProperties
Use this method to set properties into existing EntityManager that are normally passed to createEntityManager method. Note that if the method called when active persistence context already exists then properties used to create persistence context will be ignored until the new persistence context is created (that happens either after transaction rolled back or after clear method was called). -
setProperty
- Specified by:
setProperty
in interfaceEntityManager
- See Also:
-
hasActivePersistenceContext
public boolean hasActivePersistenceContext()This method is used in contains to check if we already have a persistence context. If there is no active persistence context the method returns false -
checkForTransaction
Return the current, joined transaction object. If validateExistence is true throw an error if there is no joined transaction, otherwise return null. -
shouldFlushBeforeQuery
public boolean shouldFlushBeforeQuery() -
shouldBeginEarlyTransaction
public boolean shouldBeginEarlyTransaction()Indicate the early transaction should be forced to start. This allows for reading through the write connection. As a side effect, this will also prevent anything from being cached. -
joinTransaction
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.- Specified by:
joinTransaction
in interfaceEntityManager
- Throws:
TransactionRequiredException
- if there is no transaction.
-
setRollbackOnly
protected void setRollbackOnly()Internal method. Sets transaction to rollback only. -
processProperties
protected void processProperties()Process the local EntityManager properties only. The persistence unit properties are processed by the factory. -
getPropertiesHandlerProperty
Get the local EntityManager property from the properties Map. This only searches the local Map. The persistence unit properties are processed by the EntityManagerFactory. -
getPropertiesHandlerProperty
Verifies and (if required) translates the value. -
setEntityTransactionWrapper
protected void setEntityTransactionWrapper() -
setFlushMode
Set the flush mode that applies to all objects contained in the persistence context.- Specified by:
setFlushMode
in interfaceEntityManager
-
setJTATransactionWrapper
protected void setJTATransactionWrapper() -
createConnectionPolicy
protected void createConnectionPolicy()Create connection policy using properties. Default connection policy created if no connection properties specified. Should be called only in case this.databaseSession is a ServerSession. -
createConnectionPolicies
Create connection policy using properties. Default connection policy created if no connection properties specified. Should be called only in case this.databaseSession is a SessionBroker. -
createConnectionPolicy
protected static ConnectionPolicy createConnectionPolicy(ServerSession serverSession, Map properties) Create connection policy using properties. Default connection policy created if no connection properties specified. -
isBroker
public boolean isBroker()Indicates whether the underlying session is a session broker. Session broker implement composite persistence unit.- Specified by:
isBroker
in interfaceJpaEntityManager
-
isPropertyToBeAdded
Property value is to be added if it's non null and not an empty string. -
isPropertyToBeAdded
-
isPropertyToBeRemoved
Property value of an empty string indicates that the existing property should be removed. -
isPropertyValueToBeUpdated
- Returns:
- null: no change; TRUE: substitute oldValue by newValue; FALSE: remove oldValue
-
detach
Remove the given entity from the persistence context, causing a managed entity to become detached. Unflushed changes made to the entity if any (including removal of the entity), will not be synchronized to the database. Entities which previously referenced the detached entity will continue to reference it.- Specified by:
detach
in interfaceEntityManager
- Throws:
IllegalArgumentException
- if the instance is not an entity- Since:
- Java Persistence 2.0
-
getCriteriaBuilder
Return an instance of CriteriaBuilder for the creation of Criteria API Query objects.- Specified by:
getCriteriaBuilder
in interfaceEntityManager
- Returns:
- CriteriaBuilder instance
- Throws:
IllegalStateException
- if the entity manager has been closed.- Since:
- Java Persistence 2.0
- See Also:
-
getQueryHints
protected HashMap<String,Object> getQueryHints(Object entity, EntityManagerImpl.OperationType operation) Before any find or refresh operation, gather any persistence unit properties that should be applied to the query. -
getMetamodel
Return an instance of Metamodel interface for access to the metamodel of the persistence unit.- Specified by:
getMetamodel
in interfaceEntityManager
- Returns:
- Metamodel instance
- Throws:
IllegalStateException
- if the entity manager has been closed.- Since:
- Java Persistence 2.0
- See Also:
-
getEntityManagerFactory
Return the entity manager factory for the entity manager.- Specified by:
getEntityManagerFactory
in interfaceEntityManager
- Returns:
- EntityManagerFactory instance
- Throws:
IllegalStateException
- if the entity manager has been closed.- Since:
- Java Persistence API 2.0
-
getLockMode
- Specified by:
getLockMode
in interfaceEntityManager
- Since:
- Java Persistence API 2.0
- See Also:
-
getProperties
Get the properties and associated values that are in effect for the entity manager. Changing the contents of the map does not change the configuration in effect.- Specified by:
getProperties
in interfaceEntityManager
- Since:
- Java Persistence API 2.0
-
getSupportedProperties
Get the names of the properties that are supported for use with the entity manager. These correspond to properties and hints that may be passed to the methods of the EntityManager interface that take a properties argument or used with the PersistenceContext annotation. These properties include all standard entity manager hints and properties as well as vendor-specific ones supported by the provider. These properties may or may not currently be in effect.- Returns:
- property names
- Since:
- Java Persistence API 2.0
-
unwrap
Return an object of the specified type to allow access to the provider-specific API. If the provider's EntityManager implementation does not support the specified class, the PersistenceException is thrown.- Specified by:
unwrap
in interfaceEntityManager
- Parameters:
cls
- the class of the object to be returned. This is normally either the underlying EntityManager implementation class or an interface that it implements.- Returns:
- an instance of the specified class
- Throws:
PersistenceException
- if the provider does not support the call.- Since:
- Java Persistence API 2.0
-
load
This method will load the passed entity or collection of entities using the passed AttributeGroup. In case of collection all members should be either entities of the same type or have a common inheritance hierarchy mapped root class. The AttributeGroup should correspond to the entity type.- Specified by:
load
in interfaceJpaEntityManager
-
copy
This method will return copy the passed entity using the passed AttributeGroup. In case of collection all members should be either entities of the same type or have a common inheritance hierarchy mapped root class. The AttributeGroup should correspond to the entity type.- Specified by:
copy
in interfaceJpaEntityManager
-
processUnfetchedAttribute
INTERNAL: Load/fetch the unfetched object. This method is used by the ClassWaver.. -
processUnfetchedAttributeForSet
INTERNAL: Load/fetch the unfetched object. This method is used by the ClassWeaver. -
createQuery
- Specified by:
createQuery
in interfaceEntityManager
-
createQuery
- Specified by:
createQuery
in interfaceEntityManager
-
isJoinedToTransaction
public boolean isJoinedToTransaction()- Specified by:
isJoinedToTransaction
in interfaceEntityManager
-
createEntityGraph
- Specified by:
createEntityGraph
in interfaceEntityManager
-
createEntityGraph
- Specified by:
createEntityGraph
in interfaceEntityManager
-
getEntityGraph
- Specified by:
getEntityGraph
in interfaceEntityManager
-
getEntityGraphs
- Specified by:
getEntityGraphs
in interfaceEntityManager
-
getSyncType
INTERNAL: Tracks if this EntityManager should automatically associate with the transaction or not- Returns:
- the syncType
-