Documentation

EntityManagerInterface extends ObjectManager

EntityManager interface

Table of Contents

Methods

beginTransaction()  : void
Starts a transaction on the underlying database connection.
clear()  : void
Clears the ObjectManager. All objects that are currently managed by this ObjectManager become detached.
close()  : void
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.
commit()  : void
Commits a transaction on the underlying database connection.
contains()  : bool
Checks if the object is part of the current UnitOfWork and therefore managed.
copy()  : object
Creates a copy of the given entity. Can create a shallow or a deep copy.
createNamedNativeQuery()  : NativeQuery
Creates a NativeQuery from a named native query.
createNamedQuery()  : Query
Creates a Query from a named query.
createNativeQuery()  : NativeQuery
Creates a native SQL query.
createQuery()  : Query
Creates a new Query object.
createQueryBuilder()  : QueryBuilder
Create a QueryBuilder instance
detach()  : void
Detaches an object from the ObjectManager, causing a managed object to become detached. Unflushed changes made to the object if any (including removal of the object), will not be synchronized to the database.
find()  : object|null
Finds an object by its identifier.
flush()  : void
Flushes all changes to objects that have been queued up to now to the database.
getCache()  : Cache|null
Returns the cache API for managing the second level cache regions or NULL if the cache is not enabled.
getClassMetadata()  : ClassMetadata
Returns the ClassMetadata descriptor for a class.
getConfiguration()  : Configuration
Gets the Configuration used by the EntityManager.
getConnection()  : Connection
Gets the database connection object used by the EntityManager.
getEventManager()  : EventManager
Gets the EventManager used by the EntityManager.
getExpressionBuilder()  : Expr
Gets an ExpressionBuilder used for object-oriented construction of query expressions.
getFilters()  : FilterCollection
Gets the enabled filters.
getHydrator()  : AbstractHydrator
Gets a hydrator for the given hydration mode.
getMetadataFactory()  : mixed
Gets the metadata factory used to gather the metadata of classes.
getPartialReference()  : object|null
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.
getProxyFactory()  : ProxyFactory
Gets the proxy factory used by the EntityManager to create entity proxies.
getReference()  : object|null
Gets a reference to the entity identified by the given type and identifier without actually loading it, if the entity is not yet loaded.
getRepository()  : mixed
Gets the repository for a class.
getUnitOfWork()  : UnitOfWork
Gets the UnitOfWork used by the EntityManager to coordinate operations.
hasFilters()  : bool
Checks whether the Entity Manager has filters.
initializeObject()  : void
Helper method to initialize a lazy loading proxy or persistent collection.
isFiltersStateClean()  : bool
Checks whether the state of the filter collection is clean.
isOpen()  : bool
Check if the Entity manager is open or closed.
lock()  : void
Acquire a lock on the given entity.
newHydrator()  : AbstractHydrator
Create a new instance for the given hydration mode.
persist()  : void
Tells the ObjectManager to make an instance managed and persistent.
refresh()  : void
Refreshes the persistent state of an object from the database, overriding any local changes that have not yet been persisted.
remove()  : void
Removes an object instance.
rollback()  : void
Performs a rollback on the underlying database connection.
transactional()  : mixed
Executes a function in a transaction.

Methods

beginTransaction()

Starts a transaction on the underlying database connection.

public beginTransaction() : void

clear()

Clears the ObjectManager. All objects that are currently managed by this ObjectManager become detached.

public clear() : 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.

public close() : void

contains()

Checks if the object is part of the current UnitOfWork and therefore managed.

public contains(object $object) : bool
Parameters
$object : object
Return values
bool

copy()

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

public copy(object $entity[, bool $deep = false ]) : object
Parameters
$entity : object

The entity to copy.

$deep : bool = false

FALSE for a shallow copy, TRUE for a deep copy.

Tags
deprecated
2.7

This method is being removed from the ORM and won't have any replacement

throws
BadMethodCallException
Return values
object

The new entity.

createNamedQuery()

Creates a Query from a named query.

public createNamedQuery(string $name) : Query
Parameters
$name : string
Return values
Query

createQuery()

Creates a new Query object.

public createQuery([string $dql = '' ]) : Query
Parameters
$dql : string = ''

The DQL string.

Return values
Query

detach()

Detaches an object from the ObjectManager, causing a managed object to become detached. Unflushed changes made to the object if any (including removal of the object), will not be synchronized to the database.

public detach(object $object) : void

Objects which previously referenced the detached object will continue to reference it.

Parameters
$object : object

The object to detach.

find()

Finds an object by its identifier.

public find(string $className, mixed $id) : object|null

This is just a convenient shortcut for getRepository($className)->find($id).

Parameters
$className : string

The class name of the object to find.

$id : mixed

The identity of the object to find.

Tags
psalm-param

class-string<T> $className

psalm-return

T|null

template

T of object

Return values
object|null

The found object.

flush()

Flushes all changes to objects that have been queued up to now to the database.

public flush() : void

This effectively synchronizes the in-memory state of managed objects with the database.

getCache()

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

public getCache() : Cache|null
Return values
Cache|null

getClassMetadata()

Returns the ClassMetadata descriptor for a class.

public getClassMetadata(mixed $className) : ClassMetadata
Parameters
$className : mixed
Tags
psalm-param

string|class-string<T> $className

psalm-return

Mapping\ClassMetadata<T>

psalm-template

T of object

Return values
ClassMetadata

getConnection()

Gets the database connection object used by the EntityManager.

public getConnection() : Connection
Return values
Connection

getExpressionBuilder()

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

public getExpressionBuilder() : Expr

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 values
Expr

getHydrator()

Gets a hydrator for the given hydration mode.

public getHydrator(string|int $hydrationMode) : AbstractHydrator

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

Parameters
$hydrationMode : string|int
Tags
deprecated
psalm-param

string|AbstractQuery::HYDRATE_* $hydrationMode

Return values
AbstractHydrator

getMetadataFactory()

Gets the metadata factory used to gather the metadata of classes.

public getMetadataFactory() : mixed
Tags
psalm-return

ClassMetadataFactory<ClassMetadata>

getPartialReference()

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.

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

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
$entityName : string

The name of the entity type.

$identifier : mixed

The entity identifier.

Tags
psalm-param

class-string<T> $entityName

psalm-return

T|null

template

T

Return values
object|null

The (partial) entity reference

getReference()

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

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

The name of the entity type.

$id : mixed

The entity identifier.

Tags
psalm-param

class-string<T> $entityName

psalm-return

T|null

throws
ORMException
template

T

Return values
object|null

The entity reference.

getRepository()

Gets the repository for a class.

public getRepository(mixed $className) : mixed
Parameters
$className : mixed
Tags
psalm-param

class-string<T> $className

psalm-return

EntityRepository<T>

template

T of object

hasFilters()

Checks whether the Entity Manager has filters.

public hasFilters() : bool
Return values
bool

True, if the EM has a filter collection.

initializeObject()

Helper method to initialize a lazy loading proxy or persistent collection.

public initializeObject(object $obj) : void

This method is a no-op for other objects.

Parameters
$obj : object

isFiltersStateClean()

Checks whether the state of the filter collection is clean.

public isFiltersStateClean() : bool
Return values
bool

True, if the filter collection is clean.

isOpen()

Check if the Entity manager is open or closed.

public isOpen() : bool
Return values
bool

lock()

Acquire a lock on the given entity.

public lock(object $entity, int $lockMode[, int|DateTimeInterface|null $lockVersion = null ]) : void
Parameters
$entity : object
$lockMode : int
$lockVersion : int|DateTimeInterface|null = null
Tags
psalm-param

LockMode::* $lockMode

throws
OptimisticLockException
throws
PessimisticLockException

persist()

Tells the ObjectManager to make an instance managed and persistent.

public persist(object $object) : void

The object will be entered into the database as a result of the flush operation.

NOTE: The persist operation always considers objects that are not yet known to this ObjectManager as NEW. Do not pass detached objects to the persist operation.

Parameters
$object : object

The instance to make managed and persistent.

refresh()

Refreshes the persistent state of an object from the database, overriding any local changes that have not yet been persisted.

public refresh(object $object) : void
Parameters
$object : object

The object to refresh.

remove()

Removes an object instance.

public remove(object $object) : void

A removed object will be removed from the database as a result of the flush operation.

Parameters
$object : object

The object instance to remove.

transactional()

Executes a function in a transaction.

public transactional(callable $func) : mixed

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

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
$func : callable

The function to execute transactionally.

Tags
deprecated
2.10

Use instead.

Return values
mixed

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


        
On this page

Search results