public interface EntityManager
Mostly mimics the javax.persistence.EntityManager
interface and adds methods for working with views and
soft deletion.
Modifier and Type | Method and Description |
---|---|
Query |
createNativeQuery()
Create an instance of Query for executing a native SQL statement, e.g., for update or delete.
|
Query |
createNativeQuery(java.lang.String sqlString)
Create an instance of Query for executing a native SQL statement, e.g., for update or delete.
|
<T> TypedQuery<T> |
createNativeQuery(java.lang.String sqlString,
java.lang.Class<T> resultClass)
Create an instance of Query for executing a native SQL statement and map its result to an entity.
|
Query |
createQuery()
Create an instance of Query for executing a Java Persistence query language statement.
|
Query |
createQuery(java.lang.String qlString)
Create an instance of Query for executing a Java Persistence query language statement.
|
<T> TypedQuery<T> |
createQuery(java.lang.String qlString,
java.lang.Class<T> resultClass)
Create a type-safe instance of Query for executing a Java Persistence query language statement.
|
void |
fetch(Entity entity,
View view)
Deprecated.
|
<T extends Entity<K>,K> |
find(java.lang.Class<T> entityClass,
K id)
Find by primary key.
|
<T extends Entity<K>,K> |
find(java.lang.Class<T> entityClass,
K id,
java.lang.String... viewNames)
Find by primary key.
|
<T extends Entity<K>,K> |
find(java.lang.Class<T> entityClass,
K id,
View... views)
Find by primary key.
|
void |
flush()
Synchronize the persistence context to the underlying database.
|
java.sql.Connection |
getConnection() |
javax.persistence.EntityManager |
getDelegate() |
<T extends Entity<K>,K> |
getReference(java.lang.Class<T> entityClass,
K id)
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 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. |
boolean |
isSoftDeletion() |
<T extends Entity> |
merge(T entity)
Merge the state of the given entity into the current persistence context.
|
<T extends Entity> |
merge(T entity,
java.lang.String viewName)
Deprecated.
|
<T extends Entity> |
merge(T entity,
View view)
Deprecated.
|
void |
persist(Entity entity)
Make an instance managed and persistent.
|
<T extends Entity<K>,K> |
reload(java.lang.Class<T> entityClass,
K id,
java.lang.String... viewNames)
Deprecated.
|
<T extends Entity> |
reload(T entity,
java.lang.String... viewNames)
Reload an entity from DB according to a combined view defined by the given array of views.
|
<T extends Entity> |
reloadNN(T entity,
java.lang.String... viewNames)
Reload an entity from DB according to a combined view defined by the given array of views.
|
void |
remove(Entity entity)
Remove the entity instance.
|
void |
setSoftDeletion(boolean softDeletion)
Set SoftDeletion mode for this EntityManager.
|
void persist(Entity entity)
entity
- entity instancejava.lang.IllegalArgumentException
- if not an entity<T extends Entity> T merge(T entity)
If a new or patch entity (see PersistenceHelper
methods) with non-null ID is passed to merge,
EntityManager loads the corresponding object from the database and updates it with non-null values
of attributes of the passed entity. If the object does not exist in the database, the passed entity is persisted
and returned.
entity
- entity instancejava.lang.IllegalArgumentException
- if instance is not an entity or is a removed entityPersistenceHelper.isNew(Object)
,
PersistenceHelper.makePatch(BaseGenericIdEntity)
@Deprecated <T extends Entity> T merge(T entity, @Nullable View view)
com.haulmont.cuba.core.sys.EntityFetcher#fetch(Entity, View)
if needed.@Deprecated <T extends Entity> T merge(T entity, @Nullable java.lang.String viewName)
com.haulmont.cuba.core.sys.EntityFetcher#fetch(Entity, String)
if needed.void remove(Entity entity)
isSoftDeletion()
flag.entity
- entity instancejava.lang.IllegalArgumentException
- if not an entity@Nullable <T extends Entity<K>,K> T find(java.lang.Class<T> entityClass, K id)
entityClass
- entity classid
- entity idjava.lang.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@Nullable <T extends Entity<K>,K> T find(java.lang.Class<T> entityClass, K id, View... views)
Due to accepting views, this method actually executes a Query
which may lead to flushing of the
persistence context and invoking listeners on modified entities.
entityClass
- entity classid
- entity idviews
- array of viewsjava.lang.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@Nullable <T extends Entity<K>,K> T find(java.lang.Class<T> entityClass, K id, java.lang.String... viewNames)
Due to accepting views, this method actually executes a Query
which may lead to flushing of the
persistence context and invoking listeners on modified entities.
entityClass
- entity classid
- entity idviewNames
- array of view names for this entityjava.lang.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<T extends Entity<K>,K> T getReference(java.lang.Class<T> entityClass, K id)
entityClass
- entity classid
- entity idjava.lang.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 keyjavax.persistence.EntityNotFoundException
- if the entity state cannot be accessedQuery createQuery()
Query createQuery(java.lang.String qlString)
qlString
- a Java Persistence query string<T> TypedQuery<T> createQuery(java.lang.String qlString, java.lang.Class<T> resultClass)
qlString
- a Java Persistence query stringresultClass
- expected result classQuery createNativeQuery()
Query createNativeQuery(java.lang.String sqlString)
sqlString
- a native SQL query string<T> TypedQuery<T> createNativeQuery(java.lang.String sqlString, java.lang.Class<T> resultClass)
sqlString
- a native SQL query stringresultClass
- expected result class@Nullable <T extends Entity> T reload(T entity, java.lang.String... viewNames)
entity
- entity instance to reloadviewNames
- array of view names<T extends Entity> T reloadNN(T entity, java.lang.String... viewNames)
entity
- entity instance to reloadviewNames
- array of view namesjavax.persistence.EntityNotFoundException
- if the entity has been deletedvoid flush()
boolean isSoftDeletion()
void setSoftDeletion(boolean softDeletion)
softDeletion
- modejava.sql.Connection getConnection()
Don't close this connection after use, it will be automatically closed on transaction end.
javax.persistence.EntityManager getDelegate()
@Deprecated @Nullable <T extends Entity<K>,K> T reload(java.lang.Class<T> entityClass, K id, java.lang.String... viewNames)
find(Class, Object, String...)