Class EntityManagerImpl
- java.lang.Object
-
- org.eclipse.persistence.internal.jpa.EntityManagerImpl
-
- All Implemented Interfaces:
jakarta.persistence.EntityManager,AutoCloseable,JpaEntityManager
public class EntityManagerImpl extends Object implements 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
- Author:
- gyorke
- See Also:
EntityManager,JpaEntityManager
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classEntityManagerImpl.OperationType
-
Field Summary
Fields Modifier and Type Field Description protected booleanbeginEarlyTransactionJoin existing transaction property, allows reading through write connection.protected booleancacheStoreBypassProperty to avoid writing to the cache on commit (merge)protected booleancloseOnCommitProperty to avoid resuming unit of work if going to be closed on commit anyway.protected UnitOfWork.CommitOrderTypecommitOrderAllow updates to be ordered by id to avoid possible deadlocks.protected booleancommitWithoutPersistRulesprotected Map<String,ConnectionPolicy>connectionPoliciesIn case of composite persistence unit this map is used instead of connectionPolicy attribute.protected ConnectionPolicyconnectionPolicyConnection policy used to create ClientSession, allows using a different pool/connection/exclusive connections.protected AbstractSessiondatabaseSessionReferences the DatabaseSession that this deployment is using.protected RepeatableWriteUnitOfWorkextendedPersistenceContextStores the UnitOfWork representing the persistence context.protected EntityManagerFactoryDelegatefactoryReferences to the parent factory that has created this entity manager.protected StringflushClearCacheThe FlashClearCache mode to be used.protected jakarta.persistence.FlushModeTypeflushModeFlush mode property, allows flush before query to be avoided.protected booleanisOpenStore if this entity manager has been closed.protected WeakHashMap<QueryImpl,QueryImpl>openQueriesMapKeep a list of openQueries that are executed in this entity manager.protected booleanpersistOnCommitProperty to avoid discover new objects in unit of work if application always uses persist.protected Map<String,Object>propertiesLocal properties passed from createEntityManager.protected AbstractSessionreadOnlySessionStores a session used for read-only queries.protected ReferenceModereferenceModeReference mode property, allows weak unit of work references to allow garbage collection during a transaction.protected booleanshouldValidateExistenceDetermine if does-exist should be performed on persist.protected jakarta.persistence.SynchronizationTypesyncTypeTracks if this EntityManager should automatically associate with the transaction or not
-
Constructor Summary
Constructors Constructor Description EntityManagerImpl(String sessionName)Constructor returns an EntityManager assigned to the a particular DatabaseSession.EntityManagerImpl(EntityManagerFactoryDelegate factory, Map properties, jakarta.persistence.SynchronizationType syncType)Constructor called from the EntityManagerFactory to create an EntityManagerEntityManagerImpl(AbstractSession databaseSession, jakarta.persistence.SynchronizationType syncType)Constructor called from the EntityManagerFactory to create an EntityManagerEntityManagerImpl(AbstractSession databaseSession, Map properties, jakarta.persistence.SynchronizationType syncType)Constructor called from the EntityManagerFactory to create an EntityManager
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddOpenQuery(QueryImpl query)Queries that leave the connection and are executed against this entity manager will be added here.protected ObjectcheckForTransaction(boolean validateExistence)Return the current, joined transaction object.voidclear()Clear the persistence context, causing all managed entities to become detached.voidclose()Closes this EntityManager.protected voidcloseOpenQueries()Close any open queries executed against this entity manager.0booleancontains(Object entity)Check if the instance belongs to the current persistence context.protected booleancontains(Object entity, UnitOfWork uow)Check if the instance belongs to the current persistence context.Objectcopy(Object entityOrEntities, AttributeGroup group)This method will return copy the passed entity using the passed AttributeGroup.protected voidcreateConnectionPolicies(Map mapOfProperties)Create connection policy using properties.protected voidcreateConnectionPolicy()Create connection policy using properties.protected static ConnectionPolicycreateConnectionPolicy(ServerSession serverSession, Map properties)Create connection policy using properties.jakarta.persistence.QuerycreateDescriptorNamedQuery(String queryName, Class<?> descriptorClass)This method will create a query object that wraps a EclipseLink Named Query.jakarta.persistence.QuerycreateDescriptorNamedQuery(String queryName, Class<?> descriptorClass, List argumentTypes)This method will create a query object that wraps a EclipseLink Named Query.<T> jakarta.persistence.EntityGraph<T>createEntityGraph(Class<T> rootType)jakarta.persistence.EntityGraphcreateEntityGraph(String graphName)jakarta.persistence.QuerycreateNamedQuery(String name)Create an instance of Query for executing a named query (in EJBQL or native SQL).<T> jakarta.persistence.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).jakarta.persistence.StoredProcedureQuerycreateNamedStoredProcedureQuery(String name)Create an instance of StoredProcedureQuery for executing a stored procedure in the database.jakarta.persistence.QuerycreateNativeQuery(String sqlString)Create an instance of Query for executing a native SQL query.jakarta.persistence.QuerycreateNativeQuery(String sqlString, Class resultType)This method is used to create a query using SQL.jakarta.persistence.QuerycreateNativeQuery(String sqlString, String resultSetMapping)Create an instance of Query for executing a native SQL query.jakarta.persistence.QuerycreateQuery(jakarta.persistence.criteria.CriteriaDelete deleteQuery)<T> jakarta.persistence.TypedQuery<T>createQuery(jakarta.persistence.criteria.CriteriaQuery<T> criteriaQuery)jakarta.persistence.QuerycreateQuery(jakarta.persistence.criteria.CriteriaUpdate updateQuery)jakarta.persistence.QuerycreateQuery(String jpqlString)Create an instance of Query for executing an JPQL query.<T> jakarta.persistence.TypedQuery<T>createQuery(String qlString, Class<T> resultClass)Create an instance of TypedQuery for executing a Java Persistence query language statement.jakarta.persistence.QuerycreateQuery(Expression expression, Class<?> resultType)This method is used to create a query using a EclipseLink Expression and the return type.jakarta.persistence.QuerycreateQuery(Call call)This method is used to create a query using a EclipseLink Call.jakarta.persistence.QuerycreateQuery(Call call, Class<?> entityClass)This method is used to create a query using a EclipseLink Call.jakarta.persistence.QuerycreateQuery(DatabaseQuery databaseQuery)This method is used to create a query using a EclipseLink DatabaseQuery.jakarta.persistence.QuerycreateQueryByExample(Object exampleObject)This method is used to create a query using a EclipseLink by example.protected DatabaseQuerycreateQueryInternal(Expression expression, Class<?> resultType)This method is used to create a query using a EclipseLink Expression and the return type.jakarta.persistence.StoredProcedureQuerycreateStoredProcedureQuery(String procedureName)Create an instance ofStoredProcedureQueryfor executing a stored procedure in the database.jakarta.persistence.StoredProcedureQuerycreateStoredProcedureQuery(String procedureName, Class... resultClasses)Create an instance ofStoredProcedureQueryfor executing a stored procedure in the database.jakarta.persistence.StoredProcedureQuerycreateStoredProcedureQuery(String procedureName, String... resultSetMappings)Create an instance ofStoredProcedureQueryfor executing a stored procedure in the database.voiddetach(Object entity)Remove the given entity from the persistence context, causing a managed entity to become detached.protected voiddetectTransactionWrapper()<T> Tfind(Class<T> entityClass, Object primaryKey)Find by primary key.<T> Tfind(Class<T> entityClass, Object primaryKey, jakarta.persistence.LockModeType lockMode)Find by primary key and lock.<T> Tfind(Class<T> entityClass, Object primaryKey, jakarta.persistence.LockModeType lockMode, Map<String,Object> properties)Find by primary key and lock.<T> Tfind(Class<T> entityClass, Object primaryKey, Map<String,Object> properties)Find by primary key, using the specified properties.Objectfind(String entityName, Object primaryKey)Find by primary key.protected ObjectfindInternal(ClassDescriptor descriptor, AbstractSession session, Object id, jakarta.persistence.LockModeType lockMode, Map<String,Object> properties)Find by primary key.voidflush()Synchronize the persistence context with the underlying database.AbstractSessiongetAbstractSession()Return the underlying database sessionRepeatableWriteUnitOfWorkgetActivePersistenceContext(Object txn)SessiongetActiveSession()This method returns the current session to the requestor.AbstractSessiongetActiveSessionIfExists()This method returns the current session to the requestor.jakarta.persistence.criteria.CriteriaBuildergetCriteriaBuilder()Return an instance of CriteriaBuilder for the creation of Criteria API Query objects.DatabaseSessionImplgetDatabaseSession()Return the underlying database sessionObjectgetDelegate()Return the underlying provider object for the EntityManager, if available.jakarta.persistence.EntityGraphgetEntityGraph(String graphName)<T> List<jakarta.persistence.EntityGraph<? super T>>getEntityGraphs(Class<T> entityClass)jakarta.persistence.EntityManagerFactorygetEntityManagerFactory()Return the entity manager factory for the entity manager.jakarta.persistence.FlushModeTypegetFlushMode()Get the flush mode that applies to all objects contained in the persistence context.jakarta.persistence.LockModeTypegetLockMode(Object entity)DatabaseSessionImplgetMemberDatabaseSession(Class<?> cls)Return the member DatabaseSessionImpl that maps cls in session broker.ServerSessiongetMemberServerSession(Class<?> cls)Return the member ServerSession that maps cls in session broker.StringgetMemberSessionName(Class<?> cls)Return the name of member session that maps cls.jakarta.persistence.metamodel.MetamodelgetMetamodel()Return an instance of Metamodel interface for access to the metamodel of the persistence unit.protected Map<QueryImpl,QueryImpl>getOpenQueriesMap()Return the weak reference to the open queries.protected Set<QueryImpl>getOpenQueriesSet()Return the weak reference to the open queries.Map<String,Object>getProperties()Get the properties and associated values that are in effect for the entity manager.protected StringgetPropertiesHandlerProperty(String name)Get the local EntityManager property from the properties Map.protected static StringgetPropertiesHandlerProperty(String name, String value)Verifies and (if required) translates the value.ObjectgetProperty(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.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.protected ReadObjectQuerygetReadObjectQuery(Class<?> referenceClass, Object primaryKey, Map properties)Build a selection query for the primary key values.protected ReadObjectQuerygetReadObjectQuery(Object entity, Map properties)Build a selection query for the given entity.protected ReadObjectQuerygetReadObjectQuery(Map properties)Build a selection query using the given properties.SessiongetReadOnlySession()Return a read-only session (client session) for read-only operations.<T> TgetReference(Class<T> entityClass, Object primaryKey)Get an instance, whose state may be lazily fetched.ServerSessiongetServerSession()Return the underlying server session, throws ClassCastException if it's not a ServerSession.SessiongetSession()This method will return a Session outside of a transaction and null within a transaction.SessionBrokergetSessionBroker()Return the underlying session broker, throws ClassCastException if it's not a SessionBroker.Set<String>getSupportedProperties()Get the names of the properties that are supported for use with the entity manager.jakarta.persistence.SynchronizationTypegetSyncType()INTERNAL: Tracks if this EntityManager should automatically associate with the transaction or notjakarta.persistence.EntityTransactiongetTransaction()Returns the resource-level transaction object.UnitOfWorkgetUnitOfWork()This method will return the active UnitOfWorkbooleanhasActivePersistenceContext()This method is used in contains to check if we already have a persistence context.protected voidinitialize(Map properties)Initialize the state after construction.booleanisBroker()Indicates whether the underlying session is a session broker.booleanisFlushModeAUTO()Internal method.booleanisJoinedToTransaction()booleanisOpen()Indicates whether or not this entity manager and its entity manager factory are open.protected static booleanisPropertyToBeAdded(String value)Property value is to be added if it's non null and not an empty string.protected static booleanisPropertyToBeAdded(DataSource ds, String dsName)protected static booleanisPropertyToBeRemoved(String value)Property value of an empty string indicates that the existing property should be removed.protected static BooleanisPropertyValueToBeUpdated(String oldValue, String newValue)voidjoinTransaction()Indicate to the EntityManager that a JTA transaction is active.voidload(Object entityOrEntities, AttributeGroup group)This method will load the passed entity or collection of entities using the passed AttributeGroup.voidlock(Object entity, jakarta.persistence.LockModeType lockMode)Set the lock mode for an entity object contained in the persistence context.voidlock(Object entity, jakarta.persistence.LockModeType lockMode, Map<String,Object> properties)Set the lock mode for an entity object contained in the persistence context.<T> Tmerge(T entity)Merge the state of the given entity into the current persistence context, using the unqualified class name as the entity name.protected ObjectmergeInternal(Object entity)Merge the state of the given entity into the current persistence context, using the unqualified class name as the entity name.voidpersist(Object entity)If in a transaction this method will check for existence and register the object if it is new.protected voidprocessProperties()Process the local EntityManager properties only.static voidprocessUnfetchedAttribute(FetchGroupTracker entity, String attributeName)INTERNAL: Load/fetch the unfetched object.static voidprocessUnfetchedAttributeForSet(FetchGroupTracker entity, String attributeName)INTERNAL: Load/fetch the unfetched object.voidrefresh(Object entity)Refresh the state of the instance from the database.voidrefresh(Object entity, jakarta.persistence.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.voidrefresh(Object entity, jakarta.persistence.LockModeType lockMode, Map<String,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.voidrefresh(Object entity, Map<String,Object> properties)Refresh the state of the instance from the database, using the specified properties, and overwriting changes made to the entity, if any.voidremove(Object entity)Remove the instance.voidremoveExtendedPersistenceContext()Internal method called by EntityTransactionImpl class in case of transaction rollback.voidsetAbstractSession(AbstractSession session)INTERNAL: Set the underlying database sessionprotected voidsetEntityTransactionWrapper()voidsetFlushMode(jakarta.persistence.FlushModeType flushMode)Set the flush mode that applies to all objects contained in the persistence context.protected voidsetJTATransactionWrapper()voidsetProperties(Map properties)Use this method to set properties into existing EntityManager that are normally passed to createEntityManager method.voidsetProperty(String propertyName, Object value)protected voidsetRollbackOnly()Internal method.booleanshouldBeginEarlyTransaction()Indicate the early transaction should be forced to start.booleanshouldFlushBeforeQuery()<T> Tunwrap(Class<T> cls)Return an object of the specified type to allow access to the provider-specific API.voidverifyOpen()voidverifyOpenWithSetRollbackOnly()used to save having to constantly use a try/catch to call setRollbackOnly
-
-
-
Field Detail
-
isOpen
protected boolean isOpen
Store if this entity manager has been closed.
-
extendedPersistenceContext
protected RepeatableWriteUnitOfWork extendedPersistenceContext
Stores the UnitOfWork representing the persistence context.
-
readOnlySession
protected AbstractSession readOnlySession
Stores a session used for read-only queries.
-
databaseSession
protected AbstractSession databaseSession
References the DatabaseSession that this deployment is using.
-
factory
protected EntityManagerFactoryDelegate factory
References to the parent factory that has created this entity manager. Ensures that the factory is not garbage collected.
-
beginEarlyTransaction
protected boolean beginEarlyTransaction
Join existing transaction property, allows reading through write connection.
-
properties
protected Map<String,Object> properties
Local properties passed from createEntityManager.
-
flushMode
protected jakarta.persistence.FlushModeType flushMode
Flush mode property, allows flush before query to be avoided.
-
referenceMode
protected ReferenceMode referenceMode
Reference mode property, allows weak unit of work references to allow garbage collection during a transaction.
-
connectionPolicy
protected ConnectionPolicy 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
protected Map<String,ConnectionPolicy> 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
protected WeakHashMap<QueryImpl,QueryImpl> openQueriesMap
Keep a list of openQueries that are executed in this entity manager.
-
closeOnCommit
protected boolean closeOnCommit
Property to avoid resuming unit of work if going to be closed on commit anyway.
-
persistOnCommit
protected boolean persistOnCommit
Property to avoid discover new objects in unit of work if application always uses persist.
-
cacheStoreBypass
protected boolean cacheStoreBypass
Property to avoid writing to the cache on commit (merge)
-
flushClearCache
protected String flushClearCache
The FlashClearCache mode to be used. Relevant only in case call to flush method followed by call to clear method.- See Also:
FlushClearCache
-
shouldValidateExistence
protected boolean shouldValidateExistence
Determine if does-exist should be performed on persist.
-
commitOrder
protected UnitOfWork.CommitOrderType commitOrder
Allow updates to be ordered by id to avoid possible deadlocks.
-
commitWithoutPersistRules
protected boolean commitWithoutPersistRules
-
syncType
protected jakarta.persistence.SynchronizationType syncType
Tracks if this EntityManager should automatically associate with the transaction or not
-
-
Constructor Detail
-
EntityManagerImpl
public EntityManagerImpl(String sessionName)
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
public EntityManagerImpl(AbstractSession databaseSession, jakarta.persistence.SynchronizationType syncType)
Constructor called from the EntityManagerFactory to create an EntityManager- Parameters:
databaseSession- the databaseSession assigned to this deployment.
-
EntityManagerImpl
public EntityManagerImpl(AbstractSession databaseSession, Map properties, jakarta.persistence.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, jakarta.persistence.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 Detail
-
getOpenQueriesMap
protected Map<QueryImpl,QueryImpl> getOpenQueriesMap()
Return the weak reference to the open queries.
-
getOpenQueriesSet
protected Set<QueryImpl> getOpenQueriesSet()
Return the weak reference to the open queries.
-
addOpenQuery
public void addOpenQuery(QueryImpl query)
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
protected void initialize(Map properties)
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:
clearin interfacejakarta.persistence.EntityManager
-
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
public void persist(Object entity)
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:
persistin interfacejakarta.persistence.EntityManager- 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:
mergein interfacejakarta.persistence.EntityManager- Returns:
- the instance that the state was merged to
-
mergeInternal
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.- Returns:
- the instance that the state was merged to
- Throws:
IllegalArgumentException- if given Object is not an entity or is a removed entity
-
remove
public void remove(Object entity)
Remove the instance.- Specified by:
removein interfacejakarta.persistence.EntityManager- Throws:
IllegalArgumentException- if Object passed in is not an entity
-
find
public <T> T find(Class<T> entityClass, Object primaryKey)
Find by primary key.- Specified by:
findin interfacejakarta.persistence.EntityManager- 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
public <T> T find(Class<T> entityClass, Object primaryKey, Map<String,Object> properties)
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:
findin interfacejakarta.persistence.EntityManager- 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
public <T> T find(Class<T> entityClass, Object primaryKey, jakarta.persistence.LockModeType lockMode)
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:
findin interfacejakarta.persistence.EntityManager- 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 nulljakarta.persistence.TransactionRequiredException- if there is no transaction and a lock mode other than NONE is setjakarta.persistence.OptimisticLockException- if the optimistic version check failsjakarta.persistence.PessimisticLockException- if pessimistic locking fails and the transaction is rolled backjakarta.persistence.LockTimeoutException- if pessimistic locking fails and only the statement is rolled backjakarta.persistence.PersistenceException- if an unsupported lock call is made
-
find
public <T> T find(Class<T> entityClass, Object primaryKey, jakarta.persistence.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:
findin interfacejakarta.persistence.EntityManager- 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 nulljakarta.persistence.TransactionRequiredException- if there is no transaction and a lock mode other than NONE is setjakarta.persistence.OptimisticLockException- if the optimistic version check failsjakarta.persistence.PessimisticLockException- if pessimistic locking fails and the transaction is rolled backjakarta.persistence.LockTimeoutException- if pessimistic locking fails and only the statement is rolled backjakarta.persistence.PersistenceException- if an unsupported lock call is made
-
find
public Object find(String entityName, Object primaryKey)
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, jakarta.persistence.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:
flushin interfacejakarta.persistence.EntityManager
-
detectTransactionWrapper
protected void detectTransactionWrapper()
-
refresh
public void refresh(Object entity)
Refresh the state of the instance from the database.- Specified by:
refreshin interfacejakarta.persistence.EntityManager- Parameters:
entity- instance registered in the current persistence context.
-
refresh
public void refresh(Object entity, Map<String,Object> properties)
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:
refreshin interfacejakarta.persistence.EntityManager- Parameters:
properties- standard and vendor-specific properties- Throws:
IllegalArgumentException- if the instance is not an entity or the entity is not managedjakarta.persistence.TransactionRequiredException- if invoked on a container-managed entity manager of type PersistenceContextType.TRANSACTION and there is no transaction.jakarta.persistence.EntityNotFoundException- if the entity no longer exists in the database- Since:
- Java Persistence API 2.0
-
refresh
public void refresh(Object entity, jakarta.persistence.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. 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:
refreshin interfacejakarta.persistence.EntityManager- Throws:
IllegalArgumentException- if the instance is not an entity or the entity is not managedjakarta.persistence.TransactionRequiredException- if there is no transactionjakarta.persistence.EntityNotFoundException- if the entity no longer exists in the databasejakarta.persistence.PessimisticLockException- if pessimistic locking fails and the transaction is rolled backjakarta.persistence.LockTimeoutException- if pessimistic locking fails and only the statement is rolled backjakarta.persistence.PersistenceException- if an unsupported lock call is made
-
refresh
public void refresh(Object entity, jakarta.persistence.LockModeType lockMode, Map<String,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. 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:
refreshin interfacejakarta.persistence.EntityManager- Parameters:
properties- standard and vendor-specific properties and hints- Throws:
IllegalArgumentException- if the instance is not an entity or the entity is not managedjakarta.persistence.TransactionRequiredException- if there is no transactionjakarta.persistence.EntityNotFoundException- if the entity no longer exists in the databasejakarta.persistence.PessimisticLockException- if pessimistic locking fails and the transaction is rolled backjakarta.persistence.LockTimeoutException- if pessimistic locking fails and only the statement is rolled backjakarta.persistence.PersistenceException- if an unsupported lock call is made
-
contains
public boolean contains(Object entity)
Check if the instance belongs to the current persistence context.- Specified by:
containsin interfacejakarta.persistence.EntityManager- Throws:
IllegalArgumentException- if given Object is not an entity
-
contains
protected boolean contains(Object entity, UnitOfWork uow)
Check if the instance belongs to the current persistence context.
-
createDescriptorNamedQuery
public jakarta.persistence.Query createDescriptorNamedQuery(String queryName, Class<?> descriptorClass)
Description copied from interface:JpaEntityManagerThis method will create a query object that wraps a EclipseLink Named Query.- Specified by:
createDescriptorNamedQueryin interfaceJpaEntityManager
-
createDescriptorNamedQuery
public jakarta.persistence.Query createDescriptorNamedQuery(String queryName, Class<?> descriptorClass, List argumentTypes)
Description copied from interface:JpaEntityManagerThis method will create a query object that wraps a EclipseLink Named Query.- Specified by:
createDescriptorNamedQueryin interfaceJpaEntityManager
-
createNamedQuery
public jakarta.persistence.Query createNamedQuery(String name)
Create an instance of Query for executing a named query (in EJBQL or native SQL).- Specified by:
createNamedQueryin interfacejakarta.persistence.EntityManager- Parameters:
name- the name of a query defined in metadata- Returns:
- the new query instance
-
createNamedQuery
public <T> jakarta.persistence.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).- Specified by:
createNamedQueryin interfacejakarta.persistence.EntityManager- 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
public jakarta.persistence.StoredProcedureQuery createNamedStoredProcedureQuery(String name)
Create an instance of StoredProcedureQuery for executing a stored procedure in the database.- Specified by:
createNamedStoredProcedureQueryin interfacejakarta.persistence.EntityManager- 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
public jakarta.persistence.Query createNativeQuery(String sqlString)
Create an instance of Query for executing a native SQL query.- Specified by:
createNativeQueryin interfacejakarta.persistence.EntityManager- Parameters:
sqlString- a native SQL query string- Returns:
- the new query instance
-
createNativeQuery
public jakarta.persistence.Query createNativeQuery(String sqlString, Class resultType)
This method is used to create a query using SQL. The class, must be the expected return type.- Specified by:
createNativeQueryin interfacejakarta.persistence.EntityManager
-
createNativeQuery
public jakarta.persistence.Query createNativeQuery(String sqlString, String resultSetMapping)
Create an instance of Query for executing a native SQL query.- Specified by:
createNativeQueryin interfacejakarta.persistence.EntityManager- 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
public Session 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:
getActiveSessionin interfaceJpaEntityManager
-
getActiveSessionIfExists
public AbstractSession 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
public Object getDelegate()
Return the underlying provider object for the EntityManager, if available. The result of this method is implementation specific.- Specified by:
getDelegatein interfacejakarta.persistence.EntityManager
-
getFlushMode
public jakarta.persistence.FlushModeType getFlushMode()
Get the flush mode that applies to all objects contained in the persistence context.- Specified by:
getFlushModein interfacejakarta.persistence.EntityManager- Returns:
- flushMode
-
getUnitOfWork
public UnitOfWork getUnitOfWork()
This method will return the active UnitOfWork- Specified by:
getUnitOfWorkin interfaceJpaEntityManager
-
getSession
public Session getSession()
This method will return a Session outside of a transaction and null within a transaction.- Specified by:
getSessionin interfaceJpaEntityManager
-
getTransaction
public jakarta.persistence.EntityTransaction getTransaction()
Returns the resource-level transaction object. The EntityTransaction instance may be used serially to begin and commit multiple transactions.- Specified by:
getTransactionin interfacejakarta.persistence.EntityManager- Returns:
- EntityTransaction instance
- Throws:
IllegalStateException- if invoked on a JTA EntityManager.
-
getProperty
public Object 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.
-
getReadObjectQuery
protected ReadObjectQuery getReadObjectQuery(Class<?> referenceClass, Object primaryKey, Map properties)
Build a selection query for the primary key values.
-
getReadObjectQuery
protected ReadObjectQuery getReadObjectQuery(Map properties)
Build a selection query using the given properties.
-
getReadObjectQuery
protected ReadObjectQuery getReadObjectQuery(Object entity, Map properties)
Build a selection query for the given entity.
-
getReference
public <T> 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. (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:
getReferencein interfacejakarta.persistence.EntityManager- 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.jakarta.persistence.EntityNotFoundException- if the entity state cannot be accessed.
-
getReadOnlySession
public Session getReadOnlySession()
Return a read-only session (client session) for read-only operations.
-
getDatabaseSession
public DatabaseSessionImpl getDatabaseSession()
Return the underlying database session- Specified by:
getDatabaseSessionin interfaceJpaEntityManager
-
getAbstractSession
public AbstractSession getAbstractSession()
Return the underlying database session- Specified by:
getAbstractSessionin interfaceJpaEntityManager
-
setAbstractSession
public void setAbstractSession(AbstractSession session)
INTERNAL: Set the underlying database session
-
getServerSession
public ServerSession getServerSession()
Return the underlying server session, throws ClassCastException if it's not a ServerSession.- Specified by:
getServerSessionin interfaceJpaEntityManager
-
getSessionBroker
public SessionBroker getSessionBroker()
Return the underlying session broker, throws ClassCastException if it's not a SessionBroker.- Specified by:
getSessionBrokerin interfaceJpaEntityManager
-
getMemberDatabaseSession
public DatabaseSessionImpl getMemberDatabaseSession(Class<?> cls)
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:
getMemberDatabaseSessionin interfaceJpaEntityManager
-
getMemberServerSession
public ServerSession getMemberServerSession(Class<?> cls)
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:
getMemberServerSessionin interfaceJpaEntityManager
-
getMemberSessionName
public String getMemberSessionName(Class<?> cls)
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:
getMemberSessionNamein interfaceJpaEntityManager
-
createQuery
public jakarta.persistence.Query createQuery(Expression expression, Class<?> resultType)
This method is used to create a query using a EclipseLink Expression and the return type.- Specified by:
createQueryin interfaceJpaEntityManager
-
createQuery
public jakarta.persistence.Query createQuery(DatabaseQuery databaseQuery)
This method is used to create a query using a EclipseLink DatabaseQuery.- Specified by:
createQueryin interfaceJpaEntityManager
-
createQuery
public <T> jakarta.persistence.TypedQuery<T> createQuery(jakarta.persistence.criteria.CriteriaQuery<T> criteriaQuery)
- Specified by:
createQueryin interfacejakarta.persistence.EntityManager- Since:
- Java Persistence 2.0
- See Also:
EntityManager.createQuery(jakarta.persistence.criteria.CriteriaQuery)
-
createQueryByExample
public jakarta.persistence.Query createQueryByExample(Object exampleObject)
This method is used to create a query using a EclipseLink by example.- Specified by:
createQueryByExamplein interfaceJpaEntityManager
-
createQuery
public jakarta.persistence.Query createQuery(Call call)
This method is used to create a query using a EclipseLink Call.- Specified by:
createQueryin interfaceJpaEntityManager
-
createQuery
public jakarta.persistence.Query createQuery(Call call, Class<?> entityClass)
This method is used to create a query using a EclipseLink Call.- Specified by:
createQueryin interfaceJpaEntityManager
-
createQuery
public jakarta.persistence.Query createQuery(String jpqlString)
Create an instance of Query for executing an JPQL query.- Specified by:
createQueryin interfacejakarta.persistence.EntityManager- Parameters:
jpqlString- an JPQL query string- Returns:
- the new query instance
-
createQuery
public <T> jakarta.persistence.TypedQuery<T> createQuery(String qlString, Class<T> resultClass)
Create an instance of TypedQuery for executing a Java Persistence query language statement.- Specified by:
createQueryin interfacejakarta.persistence.EntityManager- 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
protected DatabaseQuery createQueryInternal(Expression expression, Class<?> resultType)
This method is used to create a query using a EclipseLink Expression and the return type.
-
createStoredProcedureQuery
public jakarta.persistence.StoredProcedureQuery createStoredProcedureQuery(String procedureName)
Create an instance ofStoredProcedureQueryfor 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:
createStoredProcedureQueryin interfacejakarta.persistence.EntityManager- 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 jakarta.persistence.StoredProcedureQuery createStoredProcedureQuery(String procedureName, Class... resultClasses)
Create an instance ofStoredProcedureQueryfor executing a stored procedure in the database.Parameters must be registered before the stored procedure can be executed.
The
resultClassarguments must be specified in the order in which the result sets will be returned by the stored procedure invocation.- Specified by:
createStoredProcedureQueryin interfacejakarta.persistence.EntityManager- 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 jakarta.persistence.StoredProcedureQuery createStoredProcedureQuery(String procedureName, String... resultSetMappings)
Create an instance ofStoredProcedureQueryfor executing a stored procedure in the database.Parameters must be registered before the stored procedure can be executed.
The
resultSetMappingarguments must be specified in the order in which the result sets will be returned by the stored procedure invocation.- Specified by:
createStoredProcedureQueryin interfacejakarta.persistence.EntityManager- 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
IllegalStateExceptionexcept 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:
closein interfaceAutoCloseable- Specified by:
closein interfacejakarta.persistence.EntityManager
-
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. Returnstrueuntil a call toclose()is made.- Specified by:
isOpenin interfacejakarta.persistence.EntityManager
-
lock
public void lock(Object entity, jakarta.persistence.LockModeType lockMode)
Set the lock mode for an entity object contained in the persistence context.- Specified by:
lockin interfacejakarta.persistence.EntityManager- Throws:
jakarta.persistence.PersistenceException- if an unsupported lock call is madeIllegalArgumentException- if the instance is not an entity or is a detached entityjakarta.persistence.TransactionRequiredException- if there is no transaction
-
lock
public void lock(Object entity, jakarta.persistence.LockModeType lockMode, Map<String,Object> properties)
Set the lock mode for an entity object contained in the persistence context.- Specified by:
lockin interfacejakarta.persistence.EntityManager- Throws:
jakarta.persistence.PersistenceException- if an unsupported lock call is madeIllegalArgumentException- if the instance is not an entity or is a detached entityjakarta.persistence.TransactionRequiredException- 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
public RepeatableWriteUnitOfWork getActivePersistenceContext(Object txn)
-
setProperties
public void setProperties(Map properties)
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
public void setProperty(String propertyName, Object value)
- Specified by:
setPropertyin interfacejakarta.persistence.EntityManager- See Also:
EntityManager.setProperty(java.lang.String, java.lang.Object)
-
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
protected Object checkForTransaction(boolean validateExistence)
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:
joinTransactionin interfacejakarta.persistence.EntityManager- Throws:
jakarta.persistence.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
protected String getPropertiesHandlerProperty(String name)
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
protected static String getPropertiesHandlerProperty(String name, String value)
Verifies and (if required) translates the value.
-
setEntityTransactionWrapper
protected void setEntityTransactionWrapper()
-
setFlushMode
public void setFlushMode(jakarta.persistence.FlushModeType flushMode)
Set the flush mode that applies to all objects contained in the persistence context.- Specified by:
setFlushModein interfacejakarta.persistence.EntityManager
-
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
protected void createConnectionPolicies(Map mapOfProperties)
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:
isBrokerin interfaceJpaEntityManager
-
isPropertyToBeAdded
protected static boolean isPropertyToBeAdded(String value)
Property value is to be added if it's non null and not an empty string.
-
isPropertyToBeAdded
protected static boolean isPropertyToBeAdded(DataSource ds, String dsName)
-
isPropertyToBeRemoved
protected static boolean isPropertyToBeRemoved(String value)
Property value of an empty string indicates that the existing property should be removed.
-
isPropertyValueToBeUpdated
protected static Boolean isPropertyValueToBeUpdated(String oldValue, String newValue)
- Returns:
- null: no change; TRUE: substitute oldValue by newValue; FALSE: remove oldValue
-
detach
public void detach(Object entity)
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:
detachin interfacejakarta.persistence.EntityManager- Throws:
IllegalArgumentException- if the instance is not an entity- Since:
- Java Persistence 2.0
-
getCriteriaBuilder
public jakarta.persistence.criteria.CriteriaBuilder getCriteriaBuilder()
Return an instance of CriteriaBuilder for the creation of Criteria API Query objects.- Specified by:
getCriteriaBuilderin interfacejakarta.persistence.EntityManager- Returns:
- CriteriaBuilder instance
- Throws:
IllegalStateException- if the entity manager has been closed.- Since:
- Java Persistence 2.0
- See Also:
EntityManager.getCriteriaBuilder()
-
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
public jakarta.persistence.metamodel.Metamodel getMetamodel()
Return an instance of Metamodel interface for access to the metamodel of the persistence unit.- Specified by:
getMetamodelin interfacejakarta.persistence.EntityManager- Returns:
- Metamodel instance
- Throws:
IllegalStateException- if the entity manager has been closed.- Since:
- Java Persistence 2.0
- See Also:
EntityManager.getMetamodel()
-
getEntityManagerFactory
public jakarta.persistence.EntityManagerFactory getEntityManagerFactory()
Return the entity manager factory for the entity manager.- Specified by:
getEntityManagerFactoryin interfacejakarta.persistence.EntityManager- Returns:
- EntityManagerFactory instance
- Throws:
IllegalStateException- if the entity manager has been closed.- Since:
- Java Persistence API 2.0
-
getLockMode
public jakarta.persistence.LockModeType getLockMode(Object entity)
- Specified by:
getLockModein interfacejakarta.persistence.EntityManager- Since:
- Java Persistence API 2.0
- See Also:
EntityManager.getLockMode(java.lang.Object)
-
getProperties
public Map<String,Object> 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:
getPropertiesin interfacejakarta.persistence.EntityManager- Since:
- Java Persistence API 2.0
-
getSupportedProperties
public Set<String> 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
public <T> T unwrap(Class<T> cls)
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:
unwrapin interfacejakarta.persistence.EntityManager- 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:
jakarta.persistence.PersistenceException- if the provider does not support the call.- Since:
- Java Persistence API 2.0
-
load
public void load(Object entityOrEntities, AttributeGroup group)
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:
loadin interfaceJpaEntityManager
-
copy
public Object copy(Object entityOrEntities, AttributeGroup group)
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:
copyin interfaceJpaEntityManager
-
processUnfetchedAttribute
public static void processUnfetchedAttribute(FetchGroupTracker entity, String attributeName)
INTERNAL: Load/fetch the unfetched object. This method is used by the ClassWaver..
-
processUnfetchedAttributeForSet
public static void processUnfetchedAttributeForSet(FetchGroupTracker entity, String attributeName)
INTERNAL: Load/fetch the unfetched object. This method is used by the ClassWeaver.
-
createQuery
public jakarta.persistence.Query createQuery(jakarta.persistence.criteria.CriteriaUpdate updateQuery)
- Specified by:
createQueryin interfacejakarta.persistence.EntityManager
-
createQuery
public jakarta.persistence.Query createQuery(jakarta.persistence.criteria.CriteriaDelete deleteQuery)
- Specified by:
createQueryin interfacejakarta.persistence.EntityManager
-
isJoinedToTransaction
public boolean isJoinedToTransaction()
- Specified by:
isJoinedToTransactionin interfacejakarta.persistence.EntityManager
-
createEntityGraph
public <T> jakarta.persistence.EntityGraph<T> createEntityGraph(Class<T> rootType)
- Specified by:
createEntityGraphin interfacejakarta.persistence.EntityManager
-
createEntityGraph
public jakarta.persistence.EntityGraph createEntityGraph(String graphName)
- Specified by:
createEntityGraphin interfacejakarta.persistence.EntityManager
-
getEntityGraph
public jakarta.persistence.EntityGraph getEntityGraph(String graphName)
- Specified by:
getEntityGraphin interfacejakarta.persistence.EntityManager
-
getEntityGraphs
public <T> List<jakarta.persistence.EntityGraph<? super T>> getEntityGraphs(Class<T> entityClass)
- Specified by:
getEntityGraphsin interfacejakarta.persistence.EntityManager
-
getSyncType
public jakarta.persistence.SynchronizationType getSyncType()
INTERNAL: Tracks if this EntityManager should automatically associate with the transaction or not- Returns:
- the syncType
-
-