interface EntityManagerInterface implements ObjectManager (View source)

EntityManager interface

Methods

Cache|null
getCache()

Returns the cache API for managing the second level cache regions or NULL if the cache is not enabled.

Connection
getConnection()

Gets the database connection object used by the EntityManager.

getExpressionBuilder()

Gets an ExpressionBuilder used for object-oriented construction of query expressions.

void
beginTransaction()

Starts a transaction on the underlying database connection.

mixed
transactional(callable $func)

Executes a function in a transaction.

void
commit()

Commits a transaction on the underlying database connection.

void
rollback()

Performs a rollback on the underlying database connection.

createQuery(string $dql = '')

Creates a new Query object.

createNamedQuery(string $name)

Creates a Query from a named query.

createNativeQuery(string $sql, ResultSetMapping $rsm)

Creates a native SQL query.

createNamedNativeQuery(string $name)

Creates a NativeQuery from a named native query.

createQueryBuilder()

Create a QueryBuilder instance

object|null
getReference(string $entityName, mixed $id)

Gets a reference to the entity identified by the given type and identifier without actually loading it, if the entity is not yet loaded.

object|null
getPartialReference(string $entityName, mixed $identifier)

Gets a partial reference to the entity identified by the given type and identifier without actually loading it, if the entity is not yet loaded.

void
close()

Closes the EntityManager. All entities that are currently managed by this EntityManager become detached. The EntityManager may no longer be used after it is closed.

object
copy(object $entity, boolean $deep = false)

Creates a copy of the given entity. Can create a shallow or a deep copy.

void
lock(object $entity, int $lockMode, int|null $lockVersion = null)

Acquire a lock on the given entity.

EventManager
getEventManager()

Gets the EventManager used by the EntityManager.

getConfiguration()

Gets the Configuration used by the EntityManager.

bool
isOpen()

Check if the Entity manager is open or closed.

getUnitOfWork()

Gets the UnitOfWork used by the EntityManager to coordinate operations.

getHydrator(string|int $hydrationMode) deprecated

Gets a hydrator for the given hydration mode.

newHydrator(string|int $hydrationMode)

Create a new instance for the given hydration mode.

getProxyFactory()

Gets the proxy factory used by the EntityManager to create entity proxies.

getFilters()

Gets the enabled filters.

boolean
isFiltersStateClean()

Checks whether the state of the filter collection is clean.

boolean
hasFilters()

Checks whether the Entity Manager has filters.

ClassMetadata
getClassMetadata($className)

No description

Details

Cache|null getCache()

Returns the cache API for managing the second level cache regions or NULL if the cache is not enabled.

Return Value

Cache|null

Connection getConnection()

Gets the database connection object used by the EntityManager.

Return Value

Connection

Expr getExpressionBuilder()

Gets an ExpressionBuilder used for object-oriented construction of query expressions.

Example:

$qb = $em->createQueryBuilder(); $expr = $em->getExpressionBuilder(); $qb->select('u')->from('User', 'u') ->where($expr->orX($expr->eq('u.id', 1), $expr->eq('u.id', 2)));

Return Value

Expr

void beginTransaction()

Starts a transaction on the underlying database connection.

Return Value

void

mixed transactional(callable $func)

Executes a function in a transaction.

The function gets passed this EntityManager instance as an (optional) parameter.

{@link flush} is invoked prior to transaction commit.

If an exception occurs during execution of the function or flushing or transaction commit, the transaction is rolled back, the EntityManager closed and the exception re-thrown.

Parameters

callable $func The function to execute transactionally.

Return Value

mixed The non-empty value returned from the closure or true instead.

void commit()

Commits a transaction on the underlying database connection.

Return Value

void

void rollback()

Performs a rollback on the underlying database connection.

Return Value

void

Query createQuery(string $dql = '')

Creates a new Query object.

Parameters

string $dql The DQL string.

Return Value

Query

Query createNamedQuery(string $name)

Creates a Query from a named query.

Parameters

string $name

Return Value

Query

NativeQuery createNativeQuery(string $sql, ResultSetMapping $rsm)

Creates a native SQL query.

Parameters

string $sql
ResultSetMapping $rsm The ResultSetMapping to use.

Return Value

NativeQuery

NativeQuery createNamedNativeQuery(string $name)

Creates a NativeQuery from a named native query.

Parameters

string $name

Return Value

NativeQuery

QueryBuilder createQueryBuilder()

Create a QueryBuilder instance

Return Value

QueryBuilder

object|null getReference(string $entityName, mixed $id)

Gets a reference to the entity identified by the given type and identifier without actually loading it, if the entity is not yet loaded.

Parameters

string $entityName The name of the entity type.
mixed $id The entity identifier.

Return Value

object|null The entity reference.

Exceptions

ORMException

object|null getPartialReference(string $entityName, mixed $identifier)

Gets a partial reference to the entity identified by the given type and identifier without actually loading it, if the entity is not yet loaded.

The returned reference may be a partial object if the entity is not yet loaded/managed. If it is a partial object it will not initialize the rest of the entity state on access. Thus you can only ever safely access the identifier of an entity obtained through this method.

The use-cases for partial references involve maintaining bidirectional associations without loading one side of the association or to update an entity without loading it. Note, however, that in the latter case the original (persistent) entity data will never be visible to the application (especially not event listeners) as it will never be loaded in the first place.

Parameters

string $entityName The name of the entity type.
mixed $identifier The entity identifier.

Return Value

object|null The (partial) entity reference.

void close()

Closes the EntityManager. All entities that are currently managed by this EntityManager become detached. The EntityManager may no longer be used after it is closed.

Return Value

void

object copy(object $entity, boolean $deep = false)

Creates a copy of the given entity. Can create a shallow or a deep copy.

Parameters

object $entity The entity to copy.
boolean $deep FALSE for a shallow copy, TRUE for a deep copy.

Return Value

object The new entity.

Exceptions

BadMethodCallException

void lock(object $entity, int $lockMode, int|null $lockVersion = null)

Acquire a lock on the given entity.

Parameters

object $entity
int $lockMode
int|null $lockVersion

Return Value

void

Exceptions

OptimisticLockException
PessimisticLockException

EventManager getEventManager()

Gets the EventManager used by the EntityManager.

Return Value

EventManager

Configuration getConfiguration()

Gets the Configuration used by the EntityManager.

Return Value

Configuration

bool isOpen()

Check if the Entity manager is open or closed.

Return Value

bool

UnitOfWork getUnitOfWork()

Gets the UnitOfWork used by the EntityManager to coordinate operations.

Return Value

UnitOfWork

AbstractHydrator getHydrator(string|int $hydrationMode) deprecated

deprecated

Gets a hydrator for the given hydration mode.

This method caches the hydrator instances which is used for all queries that don't selectively iterate over the result.

Parameters

string|int $hydrationMode

Return Value

AbstractHydrator

AbstractHydrator newHydrator(string|int $hydrationMode)

Create a new instance for the given hydration mode.

Parameters

string|int $hydrationMode

Return Value

AbstractHydrator

Exceptions

ORMException

ProxyFactory getProxyFactory()

Gets the proxy factory used by the EntityManager to create entity proxies.

Return Value

ProxyFactory

FilterCollection getFilters()

Gets the enabled filters.

Return Value

FilterCollection The active filter collection.

boolean isFiltersStateClean()

Checks whether the state of the filter collection is clean.

Return Value

boolean True, if the filter collection is clean.

boolean hasFilters()

Checks whether the Entity Manager has filters.

Return Value

boolean True, if the EM has a filter collection.

ClassMetadata getClassMetadata($className)

Parameters

$className

Return Value

ClassMetadata