@Component(value="cuba_EntityManager") @Scope(value="prototype") public class EntityManagerImpl extends java.lang.Object implements EntityManager
NAME
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 sql)
Create an instance of Query for executing a native SQL statement, e.g., for update or delete.
|
<T extends Entity> |
createNativeQuery(java.lang.String sql,
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 qlStr)
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 |
detach(Entity entity) |
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> clazz,
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 since v.6.
|
<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.
|
public javax.persistence.EntityManager getDelegate()
getDelegate
in interface EntityManager
public boolean isSoftDeletion()
isSoftDeletion
in interface EntityManager
public void setSoftDeletion(boolean softDeletion)
EntityManager
setSoftDeletion
in interface EntityManager
softDeletion
- modepublic void persist(Entity entity)
EntityManager
persist
in interface EntityManager
entity
- entity instancepublic <T extends Entity> T merge(T entity)
EntityManager
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.
merge
in interface EntityManager
entity
- entity instancePersistenceHelper.isNew(Object)
,
PersistenceHelper.makePatch(BaseGenericIdEntity)
@Deprecated public <T extends Entity> T merge(T entity, @Nullable View view)
EntityManager
com.haulmont.cuba.core.sys.EntityFetcher#fetch(Entity, View)
if needed.merge
in interface EntityManager
@Deprecated public <T extends Entity> T merge(T entity, @Nullable java.lang.String viewName)
EntityManager
com.haulmont.cuba.core.sys.EntityFetcher#fetch(Entity, String)
if needed.merge
in interface EntityManager
public void remove(Entity entity)
EntityManager
EntityManager.isSoftDeletion()
flag.remove
in interface EntityManager
entity
- entity instancepublic <T extends Entity<K>,K> T find(java.lang.Class<T> entityClass, K id)
EntityManager
find
in interface EntityManager
entityClass
- entity classid
- entity id@Nullable public <T extends Entity<K>,K> T find(java.lang.Class<T> entityClass, K id, View... views)
EntityManager
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.
find
in interface EntityManager
entityClass
- entity classid
- entity idviews
- array of views@Nullable public <T extends Entity<K>,K> T find(java.lang.Class<T> entityClass, K id, java.lang.String... viewNames)
EntityManager
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.
find
in interface EntityManager
entityClass
- entity classid
- entity idviewNames
- array of view names for this entitypublic <T extends Entity<K>,K> T getReference(java.lang.Class<T> clazz, K id)
EntityManager
getReference
in interface EntityManager
clazz
- entity classid
- entity idpublic Query createQuery()
EntityManager
createQuery
in interface EntityManager
public Query createQuery(java.lang.String qlStr)
EntityManager
createQuery
in interface EntityManager
qlStr
- a Java Persistence query stringpublic <T> TypedQuery<T> createQuery(java.lang.String qlString, java.lang.Class<T> resultClass)
EntityManager
createQuery
in interface EntityManager
qlString
- a Java Persistence query stringresultClass
- expected result classpublic Query createNativeQuery()
EntityManager
createNativeQuery
in interface EntityManager
public Query createNativeQuery(java.lang.String sql)
EntityManager
createNativeQuery
in interface EntityManager
sql
- a native SQL query stringpublic <T extends Entity> TypedQuery<T> createNativeQuery(java.lang.String sql, java.lang.Class<T> resultClass)
EntityManager
createNativeQuery
in interface EntityManager
sql
- a native SQL query stringresultClass
- expected result class@Deprecated public void fetch(Entity entity, View view)
EntityManager
fetch
in interface EntityManager
@Nullable public <T extends Entity<K>,K> T reload(java.lang.Class<T> entityClass, K id, java.lang.String... viewNames)
EntityManager
EntityManager.find(Class, Object, String...)
reload
in interface EntityManager
@Nullable public <T extends Entity> T reload(T entity, java.lang.String... viewNames)
EntityManager
reload
in interface EntityManager
entity
- entity instance to reloadviewNames
- array of view namespublic <T extends Entity> T reloadNN(T entity, java.lang.String... viewNames)
EntityManager
reloadNN
in interface EntityManager
entity
- entity instance to reloadviewNames
- array of view namespublic void flush()
EntityManager
flush
in interface EntityManager
public void detach(Entity entity)
detach
in interface EntityManager
public java.sql.Connection getConnection()
getConnection
in interface EntityManager
Don't close this connection after use, it will be automatically closed on transaction end.