public class DbSession extends Object
Constructor and Description |
---|
DbSession(org.hibernate.SessionFactory sessionFactory) |
Modifier and Type | Method and Description |
---|---|
void |
addEventListeners(org.hibernate.SessionEventListener... listeners)
Add one or more listeners to the Session
|
org.hibernate.Transaction |
beginTransaction()
Begin a unit of work and return the associated
Transaction object. |
org.hibernate.Session.LockRequest |
buildLockRequest(org.hibernate.LockOptions lockOptions)
Build a LockRequest that specifies the LockMode, pessimistic lock timeout and lock scope.
|
org.hibernate.IdentifierLoadAccess |
byId(Class entityClass)
Create an
IdentifierLoadAccess instance to retrieve the specified entity by primary
key. |
org.hibernate.IdentifierLoadAccess |
byId(String entityName)
Create an
IdentifierLoadAccess instance to retrieve the specified entity type by
primary key. |
org.hibernate.NaturalIdLoadAccess |
byNaturalId(Class entityClass)
Create an
NaturalIdLoadAccess instance to retrieve the specified entity by its
natural id. |
org.hibernate.NaturalIdLoadAccess |
byNaturalId(String entityName)
Create an
NaturalIdLoadAccess instance to retrieve the specified entity by its
natural id. |
org.hibernate.SimpleNaturalIdLoadAccess |
bySimpleNaturalId(Class entityClass)
Create an
SimpleNaturalIdLoadAccess instance to retrieve the specified entity by its
simple (single attribute) natural id. |
org.hibernate.SimpleNaturalIdLoadAccess |
bySimpleNaturalId(String entityName)
Create an
SimpleNaturalIdLoadAccess instance to retrieve the specified entity by its
natural id. |
void |
cancelQuery()
Cancel the execution of the current query.
|
void |
clear()
Completely clear the session.
|
Connection |
close()
End the session by releasing the JDBC connection and cleaning up.
|
boolean |
contains(Object object)
Check if this instance is associated with this Session.
|
org.hibernate.Criteria |
createCriteria(Class persistentClass)
Create
Criteria instance for the given class (entity or subclasses/implementors). |
org.hibernate.Criteria |
createCriteria(Class persistentClass,
String alias)
Create
Criteria instance for the given class (entity or subclasses/implementors),
using a specific alias. |
org.hibernate.Criteria |
createCriteria(String entityName)
Create
Criteria instance for the given entity name. |
org.hibernate.Criteria |
createCriteria(String entityName,
String alias)
Create
Criteria instance for the given entity name, using a specific alias. |
org.hibernate.Query |
createFilter(Object collection,
String queryString)
Create a
Query instance for the given collection and filter string. |
org.hibernate.Query |
createQuery(String queryString)
Create a
Query instance for the given HQL query string. |
org.hibernate.SQLQuery |
createSQLQuery(String queryString)
Create a
SQLQuery instance for the given SQL query string. |
org.hibernate.procedure.ProcedureCall |
createStoredProcedureCall(String procedureName)
Creates a call to a stored procedure.
|
org.hibernate.procedure.ProcedureCall |
createStoredProcedureCall(String procedureName,
Class... resultClasses)
Creates a call to a stored procedure with specific result set entity mappings.
|
org.hibernate.procedure.ProcedureCall |
createStoredProcedureCall(String procedureName,
String... resultSetMappings)
Creates a call to a stored procedure with specific result set entity mappings.
|
void |
delete(Object object)
Remove a persistent instance from the datastore.
|
void |
delete(String entityName,
Object object)
Remove a persistent instance from the datastore.
|
void |
disableFetchProfile(String name)
Disable a particular fetch profile on this session.
|
void |
disableFilter(String filterName)
Disable the named filter for the current session.
|
<T> T |
doReturningWork(org.hibernate.jdbc.ReturningWork<T> work)
Controller for allowing users to perform JDBC related work using the Connection managed by
this Session.
|
void |
doWork(org.hibernate.jdbc.Work work)
Controller for allowing users to perform JDBC related work using the Connection managed by
this Session.
|
void |
enableFetchProfile(String name)
Enable a particular fetch profile on this session.
|
org.hibernate.Filter |
enableFilter(String filterName)
Enable the named filter for this current session.
|
void |
evict(Object object)
Remove this instance from the session cache.
|
void |
flush()
Force this session to flush.
|
Object |
get(Class clazz,
Serializable id)
Return the persistent instance of the given entity class with the given identifier, or null
if there is no such persistent instance.
|
Object |
get(Class clazz,
Serializable id,
org.hibernate.LockOptions lockOptions)
Return the persistent instance of the given entity class with the given identifier, or null
if there is no such persistent instance.
|
Object |
get(String entityName,
Serializable id)
Return the persistent instance of the given named entity with the given identifier, or null
if there is no such persistent instance.
|
Object |
get(String entityName,
Serializable id,
org.hibernate.LockOptions lockOptions)
Return the persistent instance of the given entity class with the given identifier, or null
if there is no such persistent instance.
|
org.hibernate.CacheMode |
getCacheMode()
Get the current cache mode.
|
org.hibernate.LockMode |
getCurrentLockMode(Object object)
Determine the current lock mode of the given object.
|
org.hibernate.Filter |
getEnabledFilter(String filterName)
Retrieve a currently enabled filter by name.
|
String |
getEntityName(Object object)
Return the entity name for a persistent entity.
|
org.hibernate.FlushMode |
getFlushMode()
Get the current flush mode for this session.
|
Serializable |
getIdentifier(Object object)
Return the identifier value of the given entity as associated with this session.
|
org.hibernate.LobHelper |
getLobHelper()
Retrieve this session's helper/delegate for creating LOB instances.
|
org.hibernate.procedure.ProcedureCall |
getNamedProcedureCall(String name)
Gets a ProcedureCall based on a named template
|
org.hibernate.Query |
getNamedQuery(String queryName)
Create a
Query instance for the named query string defined in the metadata. |
org.hibernate.SessionFactory |
getSessionFactory()
Get the session factory which created this session.
|
org.hibernate.stat.SessionStatistics |
getStatistics()
Get the statistics for this session.
|
String |
getTenantIdentifier()
Obtain the tenant identifier associated with this session.
|
org.hibernate.Transaction |
getTransaction()
Get the
Transaction instance associated with this session. |
org.hibernate.TypeHelper |
getTypeHelper()
Convenience access to the
TypeHelper associated with this session's
SessionFactory . |
boolean |
isConnected()
Check if the session is currently connected.
|
boolean |
isDefaultReadOnly()
Will entities and proxies that are loaded into this session be made read-only by default?
|
boolean |
isDirty()
Does this session contain any changes which must be synchronized with the database?
|
boolean |
isFetchProfileEnabled(String name)
Is a particular fetch profile enabled on this session?
|
boolean |
isOpen()
Check if the session is still open.
|
boolean |
isReadOnly(Object entityOrProxy)
Is the specified entity or proxy read-only?
|
Object |
load(Class theClass,
Serializable id)
Return the persistent instance of the given entity class with the given identifier, assuming
that the instance exists.
|
Object |
load(Class theClass,
Serializable id,
org.hibernate.LockOptions lockOptions)
Return the persistent instance of the given entity class with the given identifier, obtaining
the specified lock mode, assuming the instance exists.
|
void |
load(Object object,
Serializable id)
Read the persistent state associated with the given identifier into the given transient
instance.
|
Object |
load(String entityName,
Serializable id)
Return the persistent instance of the given entity class with the given identifier, assuming
that the instance exists.
|
Object |
load(String entityName,
Serializable id,
org.hibernate.LockOptions lockOptions)
Return the persistent instance of the given entity class with the given identifier, obtaining
the specified lock mode, assuming the instance exists.
|
Object |
merge(Object object)
Copy the state of the given object onto the persistent object with the same identifier.
|
Object |
merge(String entityName,
Object object)
Copy the state of the given object onto the persistent object with the same identifier.
|
void |
persist(Object object)
Make a transient instance persistent.
|
void |
persist(String entityName,
Object object)
Make a transient instance persistent.
|
void |
refresh(Object object)
Re-read the state of the given instance from the underlying database.
|
void |
refresh(Object object,
org.hibernate.LockOptions lockOptions)
Re-read the state of the given instance from the underlying database, with the given
LockMode.
|
void |
refresh(String entityName,
Object object)
Re-read the state of the given instance from the underlying database.
|
void |
refresh(String entityName,
Object object,
org.hibernate.LockOptions lockOptions)
Re-read the state of the given instance from the underlying database, with the given
LockMode.
|
void |
replicate(Object object,
org.hibernate.ReplicationMode replicationMode)
Persist the state of the given detached instance, reusing the current identifier value.
|
void |
replicate(String entityName,
Object object,
org.hibernate.ReplicationMode replicationMode)
Persist the state of the given detached instance, reusing the current identifier value.
|
Serializable |
save(Object object)
Persist the given transient instance, first assigning a generated identifier.
|
Serializable |
save(String entityName,
Object object)
Persist the given transient instance, first assigning a generated identifier.
|
void |
saveOrUpdate(Object object)
Either
save(Object) or update(Object) the given instance, depending upon
resolution of the unsaved-value checks (see the manual for discussion of unsaved-value
checking). |
void |
saveOrUpdate(String entityName,
Object object)
Either
save(String, Object) or update(String, Object) the given instance,
depending upon resolution of the unsaved-value checks (see the manual for discussion of
unsaved-value checking). |
org.hibernate.SharedSessionBuilder |
sessionWithOptions()
Obtain a
Session builder with the ability to grab certain information from this
session. |
void |
setCacheMode(org.hibernate.CacheMode cacheMode)
Set the cache mode.
|
void |
setDefaultReadOnly(boolean readOnly)
Change the default for entities and proxies loaded into this session from modifiable to
read-only mode, or from modifiable to read-only mode.
|
void |
setFlushMode(org.hibernate.FlushMode flushMode)
Set the flush mode for this session.
|
void |
setReadOnly(Object entityOrProxy,
boolean readOnly)
Set an unmodified persistent object to read-only mode, or a read-only object to modifiable
mode.
|
void |
update(Object object)
Update the persistent instance with the identifier of the given detached instance.
|
void |
update(String entityName,
Object object)
Update the persistent instance with the identifier of the given detached instance.
|
public String getTenantIdentifier()
null
public org.hibernate.Transaction beginTransaction()
Transaction
object. If a new
underlying transaction is required, begin the transaction. Otherwise continue the new work in
the context of the existing underlying transaction.getTransaction()
public org.hibernate.Transaction getTransaction()
Transaction
instance associated with this session. The concrete type of the
returned Transaction
object is determined by the
hibernate.transaction_factory
property.public org.hibernate.Query getNamedQuery(String queryName)
Query
instance for the named query string defined in the metadata.queryName
- the name of a query defined externallypublic org.hibernate.Query createQuery(String queryString)
Query
instance for the given HQL query string.queryString
- The HQL querypublic org.hibernate.SQLQuery createSQLQuery(String queryString)
SQLQuery
instance for the given SQL query string.queryString
- The SQL querypublic org.hibernate.procedure.ProcedureCall getNamedProcedureCall(String name)
name
- The name given to the templateNamedStoredProcedureQuery
public org.hibernate.procedure.ProcedureCall createStoredProcedureCall(String procedureName)
procedureName
- The name of the procedure.public org.hibernate.procedure.ProcedureCall createStoredProcedureCall(String procedureName, Class... resultClasses)
procedureName
- The name of the procedure.resultClasses
- The entity(s) to map the result on to.public org.hibernate.procedure.ProcedureCall createStoredProcedureCall(String procedureName, String... resultSetMappings)
procedureName
- The name of the procedure.resultSetMappings
- The explicit result set mapping(s) to use for mapping the resultspublic org.hibernate.Criteria createCriteria(Class persistentClass)
Criteria
instance for the given class (entity or subclasses/implementors).persistentClass
- The class, which is an entity, or has entity subclasses/implementorspublic org.hibernate.Criteria createCriteria(Class persistentClass, String alias)
Criteria
instance for the given class (entity or subclasses/implementors),
using a specific alias.persistentClass
- The class, which is an entity, or has entity subclasses/implementorsalias
- The alias to usepublic org.hibernate.Criteria createCriteria(String entityName)
Criteria
instance for the given entity name.entityName
- The entity name @return The criteria instance for manipulation and
executionpublic org.hibernate.Criteria createCriteria(String entityName, String alias)
Criteria
instance for the given entity name, using a specific alias.entityName
- The entity namealias
- The alias to usepublic org.hibernate.SharedSessionBuilder sessionWithOptions()
Session
builder with the ability to grab certain information from this
session.public void flush() throws org.hibernate.HibernateException
setFlushMode(FlushMode)
,
EntityTransaction.commit()
calls this method).
Flushing is the process of synchronizing the underlying persistent store with persistable state held in memory.
org.hibernate.HibernateException
- Indicates problems flushing the session or talking to the
database.public void setFlushMode(org.hibernate.FlushMode flushMode)
The flush mode determines the points at which the session is flushed. Flushing is the process of synchronizing the underlying persistent store with persistable state held in memory.
For a logically "read only" session, it is reasonable to set the session's flush mode to
FlushMode.MANUAL
at the start of the session (in order to achieve some extra
performance).
flushMode
- the new flush modeFlushMode
public org.hibernate.FlushMode getFlushMode()
public void setCacheMode(org.hibernate.CacheMode cacheMode)
Cache mode determines the manner in which this session can interact with the second level cache.
cacheMode
- The new cache mode.public org.hibernate.CacheMode getCacheMode()
public org.hibernate.SessionFactory getSessionFactory()
SessionFactory
public Connection close() throws org.hibernate.HibernateException
disconnect()
it.org.hibernate.HibernateException
- Indicates problems cleaning up.public void cancelQuery() throws org.hibernate.HibernateException
This is the sole method on session which may be safely called from another thread.
org.hibernate.HibernateException
- There was a problem canceling the querypublic boolean isOpen()
public boolean isConnected()
public boolean isDirty() throws org.hibernate.HibernateException
org.hibernate.HibernateException
- could not perform dirtying checkingpublic boolean isDefaultReadOnly()
Session.isReadOnly(Object)
public void setDefaultReadOnly(boolean readOnly)
readOnly
- true, the default for loaded entities/proxies is read-only; false, the
default for loaded entities/proxies is modifiableTo override this session's read-only/modifiable
setting for entities and proxies loaded by a Query:
,
Query.setReadOnly(boolean)
public Serializable getIdentifier(Object object)
object
- a persistent instanceorg.hibernate.TransientObjectException
- if the instance is transient or associated with a different
sessionpublic boolean contains(Object object)
object
- an instance of a persistent classpublic void evict(Object object)
object
- The entity to evictNullPointerException
- if the passed object is null
IllegalArgumentException
- if the passed object is not defined as an entitypublic Object load(Class theClass, Serializable id, org.hibernate.LockOptions lockOptions)
theClass
- a persistent classid
- a valid identifier of an existing persistent instance of the classlockOptions
- contains the lock levelpublic Object load(String entityName, Serializable id, org.hibernate.LockOptions lockOptions)
entityName
- a persistent classid
- a valid identifier of an existing persistent instance of the classlockOptions
- contains the lock levelpublic Object load(Class theClass, Serializable id)
theClass
- a persistent classid
- a valid identifier of an existing persistent instance of the classpublic Object load(String entityName, Serializable id)
entityName
- a persistent classid
- a valid identifier of an existing persistent instance of the classpublic void load(Object object, Serializable id)
object
- an "empty" instance of the persistent classid
- a valid identifier of an existing persistent instance of the classpublic void replicate(Object object, org.hibernate.ReplicationMode replicationMode)
cascade="replicate"
object
- a detached instance of a persistent classreplicationMode
- The replication mode to usepublic void replicate(String entityName, Object object, org.hibernate.ReplicationMode replicationMode)
cascade="replicate"
entityName
- The entity nameobject
- a detached instance of a persistent classreplicationMode
- The replication mode to usepublic Serializable save(Object object)
cascade="save-update"
object
- a transient instance of a persistent classpublic Serializable save(String entityName, Object object)
cascade="save-update"
entityName
- The entity nameobject
- a transient instance of a persistent classpublic void saveOrUpdate(Object object)
save(Object)
or update(Object)
the given instance, depending upon
resolution of the unsaved-value checks (see the manual for discussion of unsaved-value
checking).
This operation cascades to associated instances if the association is mapped with
cascade="save-update"
object
- a transient or detached instance containing new or updated stateSession.save(java.lang.Object)
,
Session.update(Object object)
public void saveOrUpdate(String entityName, Object object)
save(String, Object)
or update(String, Object)
the given instance,
depending upon resolution of the unsaved-value checks (see the manual for discussion of
unsaved-value checking).
This operation cascades to associated instances if the association is mapped with
cascade="save-update"
entityName
- The entity nameobject
- a transient or detached instance containing new or updated stateSession.save(String,Object)
,
Session.update(String,Object)
public void update(Object object)
cascade="save-update"
object
- a detached instance containing updated statepublic void update(String entityName, Object object)
cascade="save-update"
entityName
- The entity nameobject
- a detached instance containing updated statepublic Object merge(Object object)
cascade="merge"
The semantics of this method are defined by JSR-220.
object
- a detached instance with state to be copiedpublic Object merge(String entityName, Object object)
cascade="merge"
The semantics of this method are defined by JSR-220.
entityName
- The entity nameobject
- a detached instance with state to be copiedpublic void persist(Object object)
cascade="persist"
The semantics of this method are defined by JSR-220.
object
- a transient instance to be made persistentpublic void persist(String entityName, Object object)
cascade="persist"
The semantics of this method are defined by JSR-220.
entityName
- The entity nameobject
- a transient instance to be made persistentpublic void delete(Object object)
cascade="delete"
object
- the instance to be removedpublic void delete(String entityName, Object object)
cascade="delete"
entityName
- The entity name for the instance to be removed.object
- the instance to be removedpublic org.hibernate.Session.LockRequest buildLockRequest(org.hibernate.LockOptions lockOptions)
Example usage:
session.buildLockRequest().setLockMode(LockMode.PESSIMISTIC_WRITE).setTimeOut(60000).lock(entity);
lockOptions
- contains the lock levelpublic void refresh(Object object)
object
- a persistent or detached instancepublic void refresh(String entityName, Object object)
entityName
- a persistent classobject
- a persistent or detached instancepublic void refresh(Object object, org.hibernate.LockOptions lockOptions)
object
- a persistent or detached instancelockOptions
- contains the lock mode to usepublic void refresh(String entityName, Object object, org.hibernate.LockOptions lockOptions)
entityName
- a persistent classobject
- a persistent or detached instancelockOptions
- contains the lock mode to usepublic org.hibernate.LockMode getCurrentLockMode(Object object)
object
- a persistent instancepublic org.hibernate.Query createFilter(Object collection, String queryString)
Query
instance for the given collection and filter string. Contains an
implicit FROM
element named this
which refers to the defined table for the
collection elements, as well as an implicit WHERE
restriction for this particular
collection instance's key value.collection
- a persistent collectionqueryString
- a Hibernate query fragment.public void clear()
public Object get(Class clazz, Serializable id)
clazz
- a persistent classid
- an identifierpublic Object get(Class clazz, Serializable id, org.hibernate.LockOptions lockOptions)
clazz
- a persistent classid
- an identifierlockOptions
- the lock modepublic Object get(String entityName, Serializable id)
entityName
- the entity nameid
- an identifierpublic Object get(String entityName, Serializable id, org.hibernate.LockOptions lockOptions)
entityName
- the entity nameid
- an identifierlockOptions
- contains the lock modepublic String getEntityName(Object object)
object
- a persistent entitypublic org.hibernate.IdentifierLoadAccess byId(String entityName)
IdentifierLoadAccess
instance to retrieve the specified entity type by
primary key.entityName
- The entity name of the entity type to be retrievedorg.hibernate.HibernateException
- If the specified entity name cannot be resolved as an entity namepublic org.hibernate.IdentifierLoadAccess byId(Class entityClass)
IdentifierLoadAccess
instance to retrieve the specified entity by primary
key.entityClass
- The entity type to be retrievedorg.hibernate.HibernateException
- If the specified Class cannot be resolved as a mapped entitypublic org.hibernate.NaturalIdLoadAccess byNaturalId(String entityName)
NaturalIdLoadAccess
instance to retrieve the specified entity by its
natural id.entityName
- The entity name of the entity type to be retrievedorg.hibernate.HibernateException
- If the specified entity name cannot be resolved as an entity namepublic org.hibernate.NaturalIdLoadAccess byNaturalId(Class entityClass)
NaturalIdLoadAccess
instance to retrieve the specified entity by its
natural id.entityClass
- The entity type to be retrievedorg.hibernate.HibernateException
- If the specified Class cannot be resolved as a mapped entitypublic org.hibernate.SimpleNaturalIdLoadAccess bySimpleNaturalId(String entityName)
SimpleNaturalIdLoadAccess
instance to retrieve the specified entity by its
natural id.entityName
- The entity name of the entity type to be retrievedorg.hibernate.HibernateException
- If the specified entityClass cannot be resolved as a mapped
entity, or if the entity does not define a natural-id or if its natural-id is
made up of multiple attributes.public org.hibernate.SimpleNaturalIdLoadAccess bySimpleNaturalId(Class entityClass)
SimpleNaturalIdLoadAccess
instance to retrieve the specified entity by its
simple (single attribute) natural id.entityClass
- The entity type to be retrievedorg.hibernate.HibernateException
- If the specified entityClass cannot be resolved as a mapped
entity, or if the entity does not define a natural-id or if its natural-id is
made up of multiple attributes.public org.hibernate.Filter enableFilter(String filterName)
filterName
- The name of the filter to be enabled.public org.hibernate.Filter getEnabledFilter(String filterName)
filterName
- The name of the filter to be retrieved.public void disableFilter(String filterName)
filterName
- The name of the filter to be disabled.public org.hibernate.stat.SessionStatistics getStatistics()
public boolean isReadOnly(Object entityOrProxy)
entityOrProxy
- an entity or HibernateProxytrue
if the entity or proxy is read-only, false
if the entity or
proxy is modifiable.Session.isDefaultReadOnly()
public void setReadOnly(Object entityOrProxy, boolean readOnly)
entityOrProxy
- an entity or HibernateProxyreadOnly
- true
if the entity or proxy should be made read-only; false
if the entity or proxy should be made modifiableTo override this session's
read-only/modifiable setting for entities and proxies loaded by a Query:
,
Query.setReadOnly(boolean)
public void doWork(org.hibernate.jdbc.Work work) throws org.hibernate.HibernateException
work
- The work to be performed.org.hibernate.HibernateException
- Generally indicates wrapped SQLException
public <T> T doReturningWork(org.hibernate.jdbc.ReturningWork<T> work) throws org.hibernate.HibernateException
ReturningWork.execute(java.sql.Connection)
call.T
- The type of the result returned from the workwork
- The work to be performed.ReturningWork.execute(java.sql.Connection)
.org.hibernate.HibernateException
- Generally indicates wrapped SQLException
public boolean isFetchProfileEnabled(String name) throws org.hibernate.UnknownProfileException
name
- The name of the profile to be checked.org.hibernate.UnknownProfileException
- Indicates that the given name does not match any known
profile namesfor discussion of this feature
public void enableFetchProfile(String name) throws org.hibernate.UnknownProfileException
name
- The name of the fetch profile to be enabled.org.hibernate.UnknownProfileException
- Indicates that the given name does not match any known
profile namesfor discussion of this feature
public void disableFetchProfile(String name) throws org.hibernate.UnknownProfileException
name
- The name of the fetch profile to be disabled.org.hibernate.UnknownProfileException
- Indicates that the given name does not match any known
profile namesfor discussion of this feature
public org.hibernate.TypeHelper getTypeHelper()
TypeHelper
associated with this session's
SessionFactory
.
Equivalent to calling getSessionFactory()
.getTypeHelper()
TypeHelper
associated with this session's SessionFactory
public org.hibernate.LobHelper getLobHelper()
public void addEventListeners(org.hibernate.SessionEventListener... listeners)
listeners
- The listener(s) to addCopyright © 2024 OpenMRS Inc.. All rights reserved.