Used to interact with a persistence context. Based closely on javax.persistence.EntityManager, but automatically manages conversions between Ceylon types and corresponding Java types, without the need for JPA AttributeConverters.

An EntityManager instance is associated with a persistence context. A persistence context is a set of entity instances in which for any persistent entity identity there is a unique entity instance. Within the persistence context, the entity instances and their lifecycle are managed. The EntityManager API is used to create and remove persistent entity instances, to find entities by their primary key, and to query over entities.

The set of entities that can be managed by a given EntityManager instance is defined by a persistence unit. A persistence unit defines the set of all classes that are related or grouped by the application, and which must be colocated in their mapping to a single database.

no subtypes hierarchy

Constructors
EntityManagerSource Codeshared EntityManager(JEntityManager entityManager)
createSource Codeshared create(EntityManagerFactory entityManagerFactory, Properties properties = ...)
Parameters:
  • properties = emptyMap
Attributes
criteriaBuilderSource Codeshared CriteriaBuilder criteriaBuilder

An instance of CriteriaBuilder for the creating CriteriaQuery objects.

entityManagerSource Codeshared JEntityManager entityManager

The underlying JPA entity manager.

flushModeSource Codeshared FlushModeType flushMode

The flush mode that applies to all objects contained in the persistence context.

joinedToTransactionSource Codeshared Boolean joinedToTransaction

Determine whether the entity manager is joined to the current transaction. Returns false if the entity manager is not joined to the current transaction or if no transaction is active.

metamodelSource Codeshared Metamodel metamodel

Return an instance of the Metamodel interface for access to the metamodel of the persistence unit.

openSource Codeshared Boolean open

Determine whether the entity manager is open, returning true unless the entity manager has already been closed.

propertiesSource Codeshared Properties properties

Get the properties and hints and associated values that are in effect for this entity manager.

transactionSource Codeshared EntityTransaction transaction

Return the resource-level EntityTransaction object. The EntityTransaction instance may be used serially to begin and commit multiple transactions..

Inherited Attributes
Attributes inherited from: Object
Methods
clearSource Codeshared 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.

closeSource Codeshared void close()

Close an application-managed entity manager. After the close method has been invoked, all methods on the EntityManager instance and any TypedQuery objects obtained from it will throw the IllegalStateException except for properties, transaction, and open (which will return false). If this method is called when the entity manager is associated with an active transaction, the persistence context remains managed until the transaction completes.

containsSource Codeshared actual Boolean contains(Object entity)

Check if the instance is a managed entity instance belonging to the current persistence context.

createCriteriaSource Codeshared Criteria createCriteria()

An instance of Criteria for creating and executing criteria queries.

createCriteriaQuerySource Codeshared TypedQuery<Result> createCriteriaQuery<Result>(CriteriaQuery<Result> criteriaQuery)
given Result satisfies Object

Create an instance of TypedQuery for executing a criteria query.

createDeleteQuerySource Codeshared Query createDeleteQuery(CriteriaDelete<out Object> deleteQuery)

Create an instance of Query for executing a criteria delete query.

createEntityGraphSource Codeshared EntityGraph<Entity> createEntityGraph<Entity>(Class<Entity,Nothing> rootType)
given Entity satisfies Object

Return a mutable EntityGraph that can be used to dynamically create an EntityGraph.

createNamedEntityGraphSource Codeshared EntityGraph<out Object>? createNamedEntityGraph(String graphName)

Return a mutable copy of the named EntityGraph. If there is no entity graph with the specified name, null is returned.

createNamedQuerySource Codeshared Query createNamedQuery(String name)

Create an instance of Query for executing a named query (in the Java Persistence query language or in native SQL).

createNamedStoredProcedureQuerySource Codeshared Query createNamedStoredProcedureQuery(String name)

Create an instance of Query for executing a stored procedure in the database.

createNamedTypedQuerySource Codeshared TypedQuery<Result> createNamedTypedQuery<Result>(String name, Class<Result,Nothing> resultClass)
given Result satisfies Object

Create an instance of TypedQuery for executing a Java Persistence query language named query. The select list of the query must contain exactly one item, which must be assignable to the type specified by the resultClass argument.

createNativeMappedQuerySource Codeshared Query createNativeMappedQuery(String sqlQuery, String resultSetMapping)

Create an instance of Query for executing a native SQL query.

createNativeQuerySource Codeshared Query createNativeQuery(String sqlQuery)

Create an instance of Query for executing a native SQL DML statement, that is, an insert, update, or delete.

createNativeTypedQuerySource Codeshared TypedQuery<Result> createNativeTypedQuery<Result>(String sqlQuery, Class<Result,Nothing> resultClass)
given Result satisfies Object

Create an instance of TypedQuery for executing a native SQL query.

createQuerySource Codeshared Query createQuery(String query)

Create an instance of Query for executing a Java Persistence query language statement.

createStoredProcedureMappedQuerySource Codeshared Query createStoredProcedureMappedQuery(String procedureName, String* resultSetMappings)

Create an instance of Query for executing a stored procedure in the database. Parameters must be registered before the stored procedure can be executed. The resultSetMappings arguments must be specified in the order in which the result sets will be returned by the stored procedure invocation.

createStoredProcedureQuerySource Codeshared Query createStoredProcedureQuery(String procedureName, Class<Object,Nothing>* resultClasses)

Create an instance of Query for executing a stored procedure in the database. Parameters must be registered before the stored procedure can be executed. The resultClasses arguments must be specified in the order in which the result sets will be returned by the stored procedure invocation.

createTypedQuerySource Codeshared TypedQuery<Result> createTypedQuery<Result>(String query, Class<Result,Nothing> resultClass)
given Result satisfies Object

Create an instance of TypedQuery for executing a Java Persistence query language statement. The select list of the query must contain exactly one item, which must be assignable to the type specified by the resultClass argument.

createUpdateQuerySource Codeshared Query createUpdateQuery(CriteriaUpdate<out Object> updateQuery)

Create an instance of Query for executing a criteria update query.

destroySource Codeshared actual void destroy(Throwable? error)

Destroy this resource. Called when execution of the body of the try statement ends, even if an exception propagates out of the body of the try.

detachSource Codeshared 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.

findSource Codeshared Entity? find<Entity>(Class<Entity,Nothing> entityClass, Object primaryKey, LockModeType lockMode = ..., Properties properties = ...)
given Entity satisfies Object

Find by primary key, with the given lock mode, using the specified properties. 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.
Parameters:
  • lockMode = LockModeType.none
  • properties = emptyMap
flushSource Codeshared void flush()

Synchronize the persistence context to the underlying database, by actually executing SQL DML statements.

getEntityGraphSource Codeshared EntityGraph<out Object> getEntityGraph(String graphName)

Return a named EntityGraph. The returned EntityGraph should be considered immutable.

getEntityGraphsSource Codeshared List<EntityGraph<in Entity>> getEntityGraphs<Entity>(Class<Entity,Nothing> entityClass)
given Entity satisfies Object

Return all named EntityGraphs that have been defined for the provided class type.

getLockModeSource Codeshared LockModeType getLockMode(Object entity)

Get the current lock mode for the entity instance.

getReferenceSource Codeshared Entity getReference<Entity>(Class<Entity,Nothing> entityClass, Object primaryKey)
given Entity satisfies Object

Get an instance, whose state may be lazily fetched. If the requested instance does not exist in the database, the EntityNotFoundException is thrown when the instance state is first accessed. (The persistence provider runtime is permitted to throw the EntityNotFoundException when getReference() is called.) The application should not expect that the instance state will be available upon detachment, unless it was accessed by the application while the entity manager was open.

joinTransactionSource Codeshared void joinTransaction()

Indicate to the entity manager that a JTA transaction is active. This method should be called on a JTA application managed entity manager that was created outside the scope of the active transaction to associate it with the current JTA transaction.

lockSource Codeshared void lock(Object entity, LockModeType lockMode, Properties properties = ...)

Lock an entity instance that is contained in the persistence context with the specified lock mode type and with specified properties.

If a pessimistic lock mode type is specified and the entity contains a version attribute, the persistence provider must also perform optimistic version checks when obtaining the database lock. If these checks fail, the OptimisticLockException will be thrown.

If the lock mode type is pessimistic and the entity instance is found but cannot be locked:

  • 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.
Parameters:
  • properties = emptyMap
mergeSource Codeshared Entity merge<Entity>(Entity entity)
given Entity satisfies Object

Merge the state of the given entity into the current persistence context.

persistSource Codeshared void persist(Object entity)

Make an instance managed and persistent.

refreshSource Codeshared void refresh(Object entity, LockModeType lockMode = ..., Properties properties = ...)

Refresh the state of the instance from the database, overwriting changes made to the entity, if any, and lock it with respect to given lock mode type and with specified properties.

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.
Parameters:
  • lockMode = LockModeType.none
  • properties = emptyMap
removeSource Codeshared void remove(Object entity)

Remove the entity instance.

setPropertySource Codeshared void setProperty(String propertyName, Object propertyValue)

Set an entity manager property or hint.

Inherited Methods
Methods inherited from: Object
Methods inherited from: Category<Element>
Methods inherited from: Destroyable