Show TOC

Background documentationEntity Manager Operations Locate this document in the navigation structure

 

Basic Operations

Type

Method and operation

void

persist(Object entity)

Make an entity instance managed and persistent.

<T> T

find(Class<T> entityClass, Object primaryKey)

Find by primary key.

<T> T

merge(T entity)

Merge the state of the entity with the current persistence context.

void

remove(Object entity)

Remove the entity instance.

Basic Query Operations

Type

Method and operation

Query

createNamedQuery(String name)

Create an instance of Query for executing a named query (in JPQL or Native SQL).

Query

createQuery(String qlString)

Create an instance of Query for executing a JPQL statement.

Advanced Query Operations

Type

Method and operation

Query

createNativeQuery(String sqlString, Class resultClass)

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

Query

createNativeQuery(String sqlString, String resultSetMapping)

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

Query

createNativeQuery(String sqlString)

Create an instance of Query for executing a Native SQL statement, for example, for update or delete.

FlushModeType

getFlushMode()

Get the flush mode that applies to all objects within the persistence context.

void

setFlushMode(FlushModeType flushMode)

Set the flush mode that applies to all objects within the persistence context.

Synchronization with the Database

Type

Method and operation

void

flush()

Synchronize the persistence context with the underlying database.

void

refresh(Object entity)

Refresh the state of the instance from the database, overwriting any changes made to the entity.

Contents of the Persistence Context

Type

Method and operation

boolean

contains(Object entity)

Check if the entity instance belongs to the current persistence context.

void

clear()

Clear the persistence context, causing all managed entities to become detached.

Lifecycle of the Entity Manager

Type

Method and operation

void

close()

Close an application-managed Entity Manager.

boolean

isOpen()

Determine whether the Entity Manager is open.

Concurrency Control

Type

Method and operation

void

lock(Object entity, LockModeType lockMode)

Set the lock mode for an entity object within the persistence context.

Transactions

Type

Method and operation

EntityTransaction

getTransaction()

Returns the resource-level transaction object.

void

joinTransaction()

Indicate to the Entity Manager that a JTA transaction is active.

Other

Type

Method and operation

<T> T

getReference(Class<T> entityClass, Object primaryKey)

Get an instance which allows lazy fetching of its state.

Object

getDelegate()

Return the underlying provider object for the Entity Manager, if available.