站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > Hibernate 2.1.8 正式版 API 英文文档

SessionImpl (Hibernate API Documentation) - Hibernate 2.1.8 正式版 API 英文文档


net.sf.hibernate.impl
Class SessionImpl

java.lang.Object
  extended bynet.sf.hibernate.impl.SessionImpl
All Implemented Interfaces:
Serializable, Session, SessionImplementor

public final class SessionImpl
extends Object
implements SessionImplementor

Concrete implementation of a Session, and also the central, organizing component of Hibernate's internal implementation. As such, this class exposes two interfaces; Session itself, to the application, and SessionImplementor, to other components of Hibernate. This is where all the hard work goes on. NOT THREADSAFE

Author:
Gavin King
See Also:
Serialized Form

Nested Class Summary
static class SessionImpl.CollectionEntry
          We need an entry to tell us all about the current state of a collection with respect to its persistent state
 
Method Summary
 void addArrayHolder(ArrayHolder holder)
          associate a holder with an array - called after loading array
 void addNonExist(Key key)
           
 void addUninitializedEntity(Key key, Object object, LockMode lockMode)
          Create a "temporary" entry for a newly instantiated entity.
 void afterLoad()
           
 void afterTransactionCompletion(boolean success)
          Notify the session that the transaction completed, so we no longer own the old locks.
 void beforeLoad()
           
 Transaction beginTransaction()
          Begin a unit of work and return the associated Transaction object.
 void cancelQuery()
          Cancel execution of the current query.
 void clear()
          Completely clear the session.
 Connection close()
          End the Session by disconnecting from the JDBC connection and cleaning up.
 Connection connection()
          Get the JDBC connection.
 boolean contains(Object object)
          Check if this instance is associated with this Session.
protected  JDBCException convert(SQLException sqlException, String message)
           
 Object copy(Object object, Map copiedAlready)
           
 Criteria createCriteria(Class persistentClass)
          Create a new Criteria instance, for the given entity class.
 Query createFilter(Object collection, String queryString)
          Create a new instance of Query for the given collection and filter string.
 Query createQuery(String queryString)
          Create a new instance of Query for the given query string.
 Query createSQLQuery(String sql, String[] returnAliases, Class[] returnClasses)
          Create a new instance of Query for the given SQL string.
 Query createSQLQuery(String sql, String[] returnAliases, Class[] returnClasses, Collection querySpaces)
           
 Query createSQLQuery(String sql, String returnAlias, Class returnClass)
          Create a new instance of Query for the given SQL string.
 void delete(Object object)
          Delete a persistent object
 int delete(String query)
          Delete all objects returned by the query.
 int delete(String query, Object[] values, Type[] types)
          Delete all objects returned by the query.
 int delete(String query, Object value, Type type)
          Delete all objects returned by the query.
 Connection disconnect()
          Disconnect the Session from the current JDBC connection.
 Object doCopy(Object object, Serializable id, Map copiedAlready)
           
 void endLoadingCollections(CollectionPersister persister, Object resultSetId)
           
 void evict(Object object)
          remove any hard references to the entity that are held by the infrastructure (references held by application or other persistant instances are okay)
 Collection filter(Object collection, String filter)
          Apply a filter to a persistent collection.
 Collection filter(Object collection, String filter, Object[] values, Type[] types)
          Apply a filter to a persistent collection.
 Collection filter(Object collection, String filter, Object value, Type type)
          Apply a filter to a persistent collection.
 List filter(Object collection, String filter, QueryParameters queryParameters)
          Execute a filter
protected  void finalize()
          Just in case user forgot to commit()/cancel() or close()
 List find(CriteriaImpl criteria)
           
 List find(String query)
          Retrieve a list of persistent objects using a hibernate query
 List find(String query, Object[] values, Type[] types)
          Execute a query with bind parameters.
 List find(String query, Object value, Type type)
          Execute a query with bind parameters.
 List find(String query, QueryParameters queryParameters)
          Execute a find() query
 List findBySQL(String sqlQuery, String[] aliases, Class[] classes, QueryParameters queryParameters, Collection querySpaces)
          Execute an SQL Query
 void flush()
          Force the 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, LockMode lockMode)
          Return the persistent instance of the given entity class with the given identifier, or null if there is no such persistent instance.
 ArrayHolder getArrayHolder(Object array)
          Get the PersistentCollection object for an array
 Batcher getBatcher()
          Get the prepared statement Batcher for this session
 Serializable[] getClassBatch(Class clazz, Serializable id, int batchSize)
          Get a batch of unloaded identifiers for this class
 Object getCollection(String role, Serializable id, Object owner)
          instantiate a collection wrapper (called when loading an object)
 Serializable[] getCollectionBatch(CollectionPersister collectionPersister, Serializable id, int batchSize)
          Get a batch of uninitialized collection keys for this role
 Object getCollectionOwner(Serializable key, CollectionPersister collectionPersister)
           
 LockMode getCurrentLockMode(Object object)
          Determine the current lock mode of the given object.
 Object getEntity(Key key)
          Get the entity instance associated with the given Key
 Serializable getEntityIdentifier(Object object)
          Get the id value for an object that is actually associated with the session.
 Serializable getEntityIdentifierIfNotUnsaved(Object object)
          Used by OneToOneType and ManyToOneType to determine what id value should be used for an object that may or may not be associated with the session.
 SessionFactoryImplementor getFactory()
          Get the creating SessionFactoryImplementor
 FlushMode getFlushMode()
          Get the current flush mode.
 Serializable getIdentifier(Object object)
          Return the identifier of an entity instance cached by the Session, or throw an exception if the instance is transient or associated with a different Session.
 Serializable getLoadedCollectionKey(PersistentCollection coll)
          Get the pre-flush identifier of the collection
 PersistentCollection getLoadingCollection(CollectionPersister persister, Serializable id, Object resultSetId)
           
 LockMode getLockMode(Object object)
          Get the lock mode of the entity
 Query getNamedQuery(String queryName)
          Obtain an instance of Query for a named query string defined in the mapping file.
 Collection getOrphans(PersistentCollection coll)
          Get the collection orphans (entities which were removed from the collection)
 ClassPersister getPersister(Object object)
          Get the ClassPersister for an object
 SessionFactory getSessionFactory()
          Get the SessionFactory that created this instance.
 Serializable getSnapshot(PersistentCollection coll)
          Get the snapshot of the pre-flush collection state
 long getTimestamp()
          System time before the start of the transaction
 Object getVersion(Object entity)
          Get the current versioon of the entity
 Object immediateLoad(Class clazz, Serializable id)
          Load the data for the object with the specified id into a newly created object.
 void initializeCollection(PersistentCollection collection, boolean writing)
          called by a collection that wants to initialize itself
 void initializeEntity(Object object)
          After processing a JDBC result set, we "resolve" all the associations between the entities which were instantiated and had their state "hydrated" into an array
 void initializeNonLazyCollections()
           
 Object instantiate(ClassPersister persister, Serializable id)
          give the interceptor an opportunity to override the default instantiation
 Object instantiate(Class clazz, Serializable id)
          Instantiate the entity class, initializing with the given identifier
 Object internalLoad(Class clazz, Serializable id)
          Return the object with the specified id or throw exception if no row with that id exists.
 Object internalLoadOneToOne(Class clazz, Serializable id)
          Return the object with the specified id or null if no row with that id exists.
 boolean isConnected()
          Check if the Session is currently connected.
 boolean isDirty()
          Does this Session contain any changes which must be synchronized with the database? Would any SQL be executed if we flushed this session?
 boolean isInverseCollection(PersistentCollection collection)
          Is this the "inverse" end of a bidirectional association?
 boolean isOpen()
          Check if the Session is still open.
 boolean isSaved(Object object)
          Was this object already saved to the database?
 Iterator iterate(String query)
          Execute a query and return the results in an iterator.
 Iterator iterate(String query, Object[] values, Type[] types)
          Execute a query and return the results in an iterator.
 Iterator iterate(String query, Object value, Type type)
          Execute a query and return the results in an iterator.
 Iterator iterate(String query, QueryParameters queryParameters)
          Execute an iterate() query
 Iterator iterateFilter(Object collection, String filter, QueryParameters queryParameters)
          Iterate a filter
 Object load(Class clazz, Serializable id)
          Return the persistent instance of the given entity class with the given identifier, assuming that the instance exists.
 Object load(Class clazz, Serializable id, LockMode lockMode)
          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 loadByUniqueKey(Class clazz, String uniqueKeyPropertyName, Serializable id)
          Load an instance by a unique key that is not the primary key.
 void lock(Object object, LockMode lockMode)
          Obtain the specified lock level upon the given object.
 Object narrowProxy(Object proxy, ClassPersister persister, Key key, Object object)
          If the existing proxy is insufficiently "narrow" (derived), instantiate a new proxy and overwrite the registration of the old one.
 void postDelete(Object obj)
          After actually deleting a row, record the fact that the instance no longer exists on the database (needed for identity-column key generation)
 void postHydrate(ClassPersister persister, Serializable id, Object[] values, Object object, LockMode lockMode)
          Add the "hydrated state" (an array) of an uninitialized entity to the session.
 void postInsert(Object obj)
          After actually inserting a row, record the fact that the instance exists on the database (needed for identity-column key generation)
 void postUpdate(Object obj, Object[] updatedState, Object nextVersion)
          After actually updating a row, record the fact that the database state has been updated
 Object proxyFor(ClassPersister persister, Key key, Object impl)
          Grab the existing proxy for an instance, if one exists.
 Object proxyFor(Object impl)
          Return the existing proxy associated with the given Key, or the second argument (the entity associated with the key) if no proxy exists.
 void reconnect()
          Obtain a new JDBC connection.
 void reconnect(Connection conn)
          Reconnect to the given JDBC connection.
 void refresh(Object object)
          Re-read the state of the given instance from the underlying database.
 void refresh(Object obj, LockMode lockMode)
          Re-read the state of the given instance from the underlying database, with the given LockMode.
 void replicate(Object obj, ReplicationMode replicationMode)
          Persist all reachable transient objects, reusing the current identifier values.
 Serializable save(Object obj)
          Save a transient object.
 void save(Object obj, Serializable id)
          Save a transient object with a manually assigned ID.
 void saveOrUpdate(Object obj)
          Either save() or update() the given instance, depending upon the value of its identifier property.
 Object saveOrUpdateCopy(Object object)
          Copy the state of the given object onto the persistent object with the same identifier.
 Object saveOrUpdateCopy(Object object, Serializable id)
          Copy the state of the given object onto the persistent object with the given identifier.
 void scheduleBatchLoad(Class clazz, Serializable id)
          Register the entity as batch loadable, if enabled
 ScrollableResults scroll(String query, QueryParameters queryParameters)
          Execute a scroll() query
 void setFlushMode(FlushMode flushMode)
          Set the flush mode.
 void setLockMode(Object entity, LockMode lockMode)
          Set the lock mode of the entity to the given lock mode
 void update(Object obj)
          Update the persistent instance with the identifier of the given transient instance.
 void update(Object obj, Serializable id)
          Update the persistent state associated with the given identifier.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getBatcher

public Batcher getBatcher()
Description copied from interface: SessionImplementor
Get the prepared statement Batcher for this session

Specified by:
getBatcher in interface SessionImplementor

getFactory

public SessionFactoryImplementor getFactory()
Description copied from interface: SessionImplementor
Get the creating SessionFactoryImplementor

Specified by:
getFactory in interface SessionImplementor

getTimestamp

public long getTimestamp()
Description copied from interface: SessionImplementor
System time before the start of the transaction

Specified by:
getTimestamp in interface SessionImplementor

close

public Connection close()
                 throws HibernateException
Description copied from interface: Session
End the Session by disconnecting from the JDBC connection and cleaning up. It is not strictly necessary to close() the Session but you must at least disconnect() it.

Specified by:
close in interface Session
Returns:
the connection provided by the application or null
Throws:
HibernateException

afterTransactionCompletion

public void afterTransactionCompletion(boolean success)
Description copied from interface: SessionImplementor
Notify the session that the transaction completed, so we no longer own the old locks. (Also we should release cache softlocks.) May be called multiple times during the transaction completion process.

Specified by:
afterTransactionCompletion in interface SessionImplementor

getCurrentLockMode

public LockMode getCurrentLockMode(Object object)
                            throws HibernateException
Description copied from interface: Session
Determine the current lock mode of the given object.

Specified by:
getCurrentLockMode in interface Session
Parameters:
object - a persistent instance
Returns:
the current lock mode
Throws:
HibernateException

getLockMode

public LockMode getLockMode(Object object)
Description copied from interface: SessionImplementor
Get the lock mode of the entity

Specified by:
getLockMode in interface SessionImplementor

getEntity

public Object getEntity(Key key)
Description copied from interface: SessionImplementor
Get the entity instance associated with the given Key

Specified by:
getEntity in interface SessionImplementor

setLockMode

public void setLockMode(Object entity,
                        LockMode lockMode)
Description copied from interface: SessionImplementor
Set the lock mode of the entity to the given lock mode

Specified by:
setLockMode in interface SessionImplementor

isOpen

public boolean isOpen()
Description copied from interface: Session
Check if the Session is still open.

Specified by:
isOpen in interface Session
Returns:
boolean

save

public Serializable save(Object obj)
                  throws HibernateException
Save a transient object. An id is generated, assigned to the given object and returned.

Specified by:
save in interface Session
Parameters:
obj - a transient instance of a persistent class
Returns:
the generated identifier
Throws:
HibernateException

save

public void save(Object obj,
                 Serializable id)
          throws HibernateException
Save a transient object with a manually assigned ID.

Specified by:
save in interface Session
Parameters:
obj - a transient instance of a persistent class
id - an unused valid identifier
Throws:
HibernateException

delete

public void delete(Object object)
            throws HibernateException
Delete a persistent object

Specified by:
delete in interface Session
Parameters:
object - the instance to be removed
Throws:
HibernateException

update

public void update(Object obj)
            throws HibernateException
Description copied from interface: Session
Update the persistent instance with the identifier of the given transient instance. If there is a persistent instance with the same identifier, an exception is thrown.

If the given transient instance has a null identifier, an exception will be thrown.

Specified by:
update in interface Session
Parameters:
obj - a transient instance containing updated state
Throws:
HibernateException

saveOrUpdate

public void saveOrUpdate(Object obj)
                  throws HibernateException
Description copied from interface: Session
Either save() or update() the given instance, depending upon the value of its identifier property. By default the instance is always saved. This behaviour may be adjusted by specifying an unsaved-value attribute of the identifier property mapping.

Specified by:
saveOrUpdate in interface Session
Parameters:
obj - a transient instance containing new or updated state
Throws:
HibernateException
See Also:
Session.save(java.lang.Object), Session.update(Object object, Serializable id)

update

public void update(Object obj,
                   Serializable id)
            throws HibernateException
Description copied from interface: Session
Update the persistent state associated with the given identifier. An exception is thrown if there is a persistent instance with the same identifier in the current session.

Specified by:
update in interface Session
Parameters:
obj - a transient instance containing updated state
id - identifier of persistent instance
Throws:
HibernateException

find

public List find(String query)
          throws HibernateException
Retrieve a list of persistent objects using a hibernate query

Specified by:
find in interface Session
Parameters:
query - a query expressed in Hibernate's query language
Returns:
a distinct list of instances (or arrays of instances)
Throws:
HibernateException

find

public List find(String query,
                 Object value,
                 Type type)
          throws HibernateException
Description copied from interface: Session
Execute a query with bind parameters. Bind a value to a "?" parameter in the query string.

Specified by:
find in interface Session
Parameters:
query - the query string
value - a value to be bound to a "?" placeholder (JDBC IN parameter).
type - the Hibernate type of the value
Returns:
a distinct list of instances (or arrays of instances)
Throws:
HibernateException
See Also:
for access to Type instances

find

public List find(String query,
                 Object[] values,
                 Type[] types)
          throws HibernateException
Description copied from interface: Session
Execute a query with bind parameters. Binding an array of values to "?" parameters in the query string.

Specified by:
find in interface Session
Parameters:
query - the query string
values - an array of values to be bound to the "?" placeholders (JDBC IN parameters).
types - an array of Hibernate types of the values
Returns:
a distinct list of instances
Throws:
HibernateException
See Also:
for access to Type instances

find

public List find(String query,
                 QueryParameters queryParameters)
          throws HibernateException
Description copied from interface: SessionImplementor
Execute a find() query

Specified by:
find in interface SessionImplementor
Throws:
HibernateException

iterate

public Iterator iterate(String query)
                 throws HibernateException
Description copied from interface: Session
Execute a query and return the results in an iterator. If the query has multiple return values, values will be returned in an array of type Object[].

Entities returned as results are initialized on demand. The first SQL query returns identifiers only. So iterate() is usually a less efficient way to retrieve objects than find().

Specified by:
iterate in interface Session
Parameters:
query - the query string
Returns:
an iterator
Throws:
HibernateException

iterate

public Iterator iterate(String query,
                        Object value,
                        Type type)
                 throws HibernateException
Description copied from interface: Session
Execute a query and return the results in an iterator. Write the given value to "?" in the query string. If the query has multiple return values, values will be returned in an array of type Object[].

Entities returned as results are initialized on demand. The first SQL query returns identifiers only. So iterate() is usually a less efficient way to retrieve objects than find().

Specified by:
iterate in interface Session
Parameters:
query - the query string
value - a value to be witten to a "?" placeholder in the query string
type - the hibernate type of value
Returns:
an iterator
Throws:
HibernateException

iterate

public Iterator iterate(String query,
                        Object[] values,
                        Type[] types)
                 throws HibernateException
Description copied from interface: Session
Execute a query and return the results in an iterator. Write the given values to "?" in the query string. If the query has multiple return values, values will be returned in an array of type Object[].

Entities returned as results are initialized on demand. The first SQL query returns identifiers only. So iterate() is usually a less efficient way to retrieve objects than find().

Specified by:
iterate in interface Session
Parameters:
query - the query string
values - a list of values to be written to "?" placeholders in the query
types - a list of Hibernate types of the values
Returns:
an iterator
Throws:
HibernateException

iterate

public Iterator iterate(String query,
                        QueryParameters queryParameters)
                 throws HibernateException
Description copied from interface: SessionImplementor
Execute an iterate() query

Specified by:
iterate in interface SessionImplementor
Throws:
HibernateException

scroll

public ScrollableResults scroll(String query,
                                QueryParameters queryParameters)
                         throws HibernateException
Description copied from interface: SessionImplementor
Execute a scroll() query

Specified by:
scroll in interface SessionImplementor
Throws:
HibernateException

delete

public int delete(String query)
           throws HibernateException
Description copied from interface: Session
Delete all objects returned by the query. Return the number of objects deleted.

Specified by:
delete in interface Session
Parameters:
query - the query string
Returns:
the number of instances deleted
Throws:
HibernateException

delete

public int delete(String query,
                  Object value,
                  Type type)
           throws HibernateException
Description copied from interface: Session
Delete all objects returned by the query. Return the number of objects deleted.

Specified by:
delete in interface Session
Parameters:
query - the query string
value - a value to be witten to a "?" placeholder in the query string.
type - the hibernate type of value.
Returns:
the number of instances deleted
Throws:
HibernateException

delete

public int delete(String query,
                  Object[] values,
                  Type[] types)
           throws HibernateException
Description copied from interface: Session
Delete all objects returned by the query. Return the number of objects deleted.

Specified by:
delete in interface Session
Parameters:
query - the query string
values - a list of values to be written to "?" placeholders in the query.
types - a list of Hibernate types of the values
Returns:
the number of instances deleted
Throws:
HibernateException

lock

public void lock(Object object,
                 LockMode lockMode)
          throws HibernateException
Description copied from interface: Session
Obtain the specified lock level upon the given object. This may be used to perform a version check (LockMode.READ), to upgrade to a pessimistic lock (LockMode.UPGRADE), or to simply reassociate a transient instance with a session (LockMode.NONE).

Specified by:
lock in interface Session
Parameters:
object - a persistent or transient instance
lockMode - the lock level
Throws:
HibernateException

createFilter

public Query createFilter(Object collection,
                          String queryString)
Description copied from interface: Session
Create a new instance of Query for the given collection and filter string.

Specified by:
createFilter in interface Session
Parameters:
collection - a persistent collection
queryString - a Hibernate query
Returns:
Query

createQuery

public Query createQuery(String queryString)
Description copied from interface: Session
Create a new instance of Query for the given query string.

Specified by:
createQuery in interface Session
Parameters:
queryString - a Hibernate query
Returns:
Query

getNamedQuery

public Query getNamedQuery(String queryName)
                    throws MappingException
Description copied from interface: Session
Obtain an instance of Query for a named query string defined in the mapping file.

Specified by:
getNamedQuery in interface Session
Parameters:
queryName - the name of a query defined externally
Returns:
Query
Throws:
MappingException

instantiate

public Object instantiate(Class clazz,
                          Serializable id)
                   throws HibernateException
Description copied from interface: SessionImplementor
Instantiate the entity class, initializing with the given identifier

Specified by:
instantiate in interface SessionImplementor
Throws:
HibernateException

instantiate

public Object instantiate(ClassPersister persister,
                          Serializable id)
                   throws HibernateException
give the interceptor an opportunity to override the default instantiation

Throws:
HibernateException

setFlushMode

public void setFlushMode(FlushMode flushMode)
Description copied from interface: Session
Set the flush mode. The flush mode determines at which points Hibernate automatically flushes the session. For a readonly session, it is reasonable to set the flush mode to FlushMode.NEVER at the start of the session (in order to achieve some extra performance).

Specified by:
setFlushMode in interface Session
Parameters:
flushMode - the FlushMode
See Also:
FlushMode

getFlushMode

public FlushMode getFlushMode()
Description copied from interface: Session
Get the current flush mode.

Specified by:
getFlushMode in interface Session
Returns:
FlushMode

narrowProxy

public Object narrowProxy(Object proxy,
                          ClassPersister persister,
                          Key key,
                          Object object)
                   throws HibernateException
If the existing proxy is insufficiently "narrow" (derived), instantiate a new proxy and overwrite the registration of the old one. This breaks == and occurs only for "class" proxies rather than "interface" proxies.

Throws:
HibernateException

proxyFor

public Object proxyFor(ClassPersister persister,
                       Key key,
                       Object impl)
                throws HibernateException
Grab the existing proxy for an instance, if one exists. (otherwise return the instance)

Specified by:
proxyFor in interface SessionImplementor
Throws:
HibernateException

proxyFor

public Object proxyFor(Object impl)
                throws HibernateException
Description copied from interface: SessionImplementor
Return the existing proxy associated with the given Key, or the second argument (the entity associated with the key) if no proxy exists. (slower than the form above)

Specified by:
proxyFor in interface SessionImplementor
Throws:
HibernateException

addUninitializedEntity

public void addUninitializedEntity(Key key,
                                   Object object,
                                   LockMode lockMode)
Create a "temporary" entry for a newly instantiated entity. The entity is uninitialized, but we need the mapping from id to instance in order to guarantee uniqueness.

Specified by:
addUninitializedEntity in interface SessionImplementor

postHydrate

public void postHydrate(ClassPersister persister,
                        Serializable id,
                        Object[] values,
                        Object object,
                        LockMode lockMode)
                 throws HibernateException
Add the "hydrated state" (an array) of an uninitialized entity to the session. We don't try to resolve any associations yet, because there might be other entities waiting to be read from the JDBC result set we are currently processing

Specified by:
postHydrate in interface SessionImplementor
Throws:
HibernateException

load

public void load(Object object,
                 Serializable id)
          throws HibernateException
Description copied from interface: Session
Read the persistent state associated with the given identifier into the given transient instance.

Specified by:
load in interface Session
Parameters:
object - an "empty" instance of the persistent class
id - a valid identifier of an existing persistent instance of the class
Throws:
HibernateException

load

public Object load(Class clazz,
                   Serializable id)
            throws HibernateException
Description copied from interface: Session
Return the persistent instance of the given entity class with the given identifier, assuming that the instance exists.

You should not use this method to determine if an instance exists (use find() instead). Use this only to retrieve an instance that you assume exists, where non-existence would be an actual error.

Specified by:
load in interface Session
Parameters:
clazz - a persistent class
id - a valid identifier of an existing persistent instance of the class
Returns:
the persistent instance or proxy
Throws:
HibernateException

get

public Object get(Class clazz,
                  Serializable id)
           throws HibernateException
Description copied from interface: Session
Return the persistent instance of the given entity class with the given identifier, or null if there is no such persistent instance. (If the instance, or a proxy for the instance, is already associated with the session, return that instance or proxy.)

Specified by:
get in interface Session
Parameters:
clazz - a persistent class
id - an identifier
Returns:
a persistent instance or null
Throws:
HibernateException

immediateLoad

public Object immediateLoad(Class clazz,
                            Serializable id)
                     throws HibernateException
Load the data for the object with the specified id into a newly created object. Do NOT return a proxy.

Specified by:
immediateLoad in interface SessionImplementor
Throws:
HibernateException

internalLoadOneToOne

public Object internalLoadOneToOne(Class clazz,
                                   Serializable id)
                            throws HibernateException
Return the object with the specified id or null if no row with that id exists. Do not defer the load or return a new proxy (but do return an existing proxy). Do not check if the object was deleted.

Specified by:
internalLoadOneToOne in interface SessionImplementor
Throws:
HibernateException

internalLoad

public Object internalLoad(Class clazz,
                           Serializable id)
                    throws HibernateException
Return the object with the specified id or throw exception if no row with that id exists. Defer the load, return a new proxy or return an existing proxy if possible. Do not check if the object was deleted.

Specified by:
internalLoad in interface SessionImplementor
Throws:
HibernateException

load

public Object load(Class clazz,
                   Serializable id,
                   LockMode lockMode)
            throws HibernateException
Description copied from interface: Session
Return the persistent instance of the given entity class with the given identifier, obtaining the specified lock mode, assuming the instance exists.

Specified by:
load in interface Session
Parameters:
clazz - a persistent class
id - a valid identifier of an existing persistent instance of the class
lockMode - the lock level
Returns:
the persistent instance or proxy
Throws:
HibernateException

get

public Object get(Class clazz,
                  Serializable id,
                  LockMode lockMode)
           throws HibernateException
Description copied from interface: Session
Return the persistent instance of the given entity class with the given identifier, or null if there is no such persistent instance. Obtain the specified lock mode if the instance exists.

Specified by:
get in interface Session
Parameters:
clazz - a persistent class
id - an identifier
lockMode - the lock mode
Returns:
a persistent instance or null
Throws:
HibernateException

refresh

public void refresh(Object object)
             throws HibernateException
Description copied from interface: Session
Re-read the state of the given instance from the underlying database. It is inadvisable to use this to implement long-running sessions that span many business tasks. This method is, however, useful in certain special circumstances. For example
  • where a database trigger alters the object state upon insert or update
  • after executing direct SQL (eg. a mass update) in the same session
  • after inserting a Blob or Clob

Specified by:
refresh in interface Session
Parameters:
object - a persistent or transient instance
Throws:
HibernateException

refresh

public void refresh(Object obj,
                    LockMode lockMode)
             throws HibernateException
Description copied from interface: Session
Re-read the state of the given instance from the underlying database, with the given LockMode. It is inadvisable to use this to implement long-running sessions that span many business tasks. This method is, however, useful in certain special circumstances.

Specified by:
refresh in interface Session
Parameters:
obj - a persistent or transient instance
lockMode - the lock mode to use
Throws:
HibernateException

initializeEntity

public void initializeEntity(Object object)
                      throws HibernateException
After processing a JDBC result set, we "resolve" all the associations between the entities which were instantiated and had their state "hydrated" into an array

Specified by:
initializeEntity in interface SessionImplementor
Throws:
HibernateException

beginTransaction

public Transaction beginTransaction()
                             throws HibernateException
Description copied from interface: Session
Begin a unit of work and return the associated 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. The class of the returned Transaction object is determined by the property hibernate.transaction_factory.

Specified by:
beginTransaction in interface Session
Returns:
a Transaction instance
Throws:
HibernateException
See Also:
Transaction

flush

public void flush()
           throws HibernateException
Description copied from interface: Session
Force the Session to flush. Must be called at the end of a unit of work, before commiting the transaction and closing the session (Transaction.commit() calls this method). Flushing is the process of synchronising the underlying persistent store with persistable state held in memory.

Specified by:
flush in interface Session
Throws:
HibernateException

isDirty

public boolean isDirty()
                throws HibernateException
Description copied from interface: Session
Does this Session contain any changes which must be synchronized with the database? Would any SQL be executed if we flushed this session?

Specified by:
isDirty in interface Session
Returns:
boolean
Throws:
HibernateException

postInsert

public void postInsert(Object obj)
Description copied from interface: SessionImplementor
After actually inserting a row, record the fact that the instance exists on the database (needed for identity-column key generation)

Specified by:
postInsert in interface SessionImplementor

postDelete

public void postDelete(Object obj)
Description copied from interface: SessionImplementor
After actually deleting a row, record the fact that the instance no longer exists on the database (needed for identity-column key generation)

Specified by:
postDelete in interface SessionImplementor

postUpdate

public void postUpdate(Object obj,
                       Object[] updatedState,
                       Object nextVersion)
                throws HibernateException
Description copied from interface: SessionImplementor
After actually updating a row, record the fact that the database state has been updated

Specified by:
postUpdate in interface SessionImplementor
Throws:
HibernateException

getPersister

public ClassPersister getPersister(Object object)
                            throws MappingException
Description copied from interface: SessionImplementor
Get the ClassPersister for an object

Specified by:
getPersister in interface SessionImplementor
Throws:
MappingException

getIdentifier

public Serializable getIdentifier(Object object)
                           throws HibernateException
Description copied from interface: Session
Return the identifier of an entity instance cached by the Session, or throw an exception if the instance is transient or associated with a different Session.

Specified by:
getIdentifier in interface Session
Parameters:
object - a persistent instance
Returns:
the identifier
Throws:
HibernateException - if the Session is connected

getEntityIdentifier

public Serializable getEntityIdentifier(Object object)
Get the id value for an object that is actually associated with the session. This is a bit stricter than getEntityIdentifierIfNotUnsaved().

Specified by:
getEntityIdentifier in interface SessionImplementor

isSaved

public boolean isSaved(Object object)
                throws HibernateException
Description copied from interface: SessionImplementor
Was this object already saved to the database?

Specified by:
isSaved in interface SessionImplementor
Throws:
HibernateException

getEntityIdentifierIfNotUnsaved

public Serializable getEntityIdentifierIfNotUnsaved(Object object)
                                             throws HibernateException
Used by OneToOneType and ManyToOneType to determine what id value should be used for an object that may or may not be associated with the session. This does a "best guess" using any/all info available to use (not just the EntityEntry).

Specified by:
getEntityIdentifierIfNotUnsaved in interface SessionImplementor
Throws:
HibernateException

getLoadingCollection

public PersistentCollection getLoadingCollection(CollectionPersister persister,
                                                 Serializable id,
                                                 Object resultSetId)
                                          throws HibernateException
Specified by:
getLoadingCollection in interface SessionImplementor
Throws:
HibernateException

endLoadingCollections

public void endLoadingCollections(CollectionPersister persister,
                                  Object resultSetId)
                           throws HibernateException
Specified by:
endLoadingCollections in interface SessionImplementor
Throws:
HibernateException

beforeLoad

public void beforeLoad()
Specified by:
beforeLoad in interface SessionImplementor

afterLoad

public void afterLoad()
Specified by:
afterLoad in interface SessionImplementor

initializeNonLazyCollections

public void initializeNonLazyCollections()
                                  throws HibernateException
Specified by:
initializeNonLazyCollections in interface SessionImplementor
Throws:
HibernateException

getArrayHolder

public ArrayHolder getArrayHolder(Object array)
Description copied from interface: SessionImplementor
Get the PersistentCollection object for an array

Specified by:
getArrayHolder in interface SessionImplementor

addArrayHolder

public void addArrayHolder(ArrayHolder holder)
associate a holder with an array - called after loading array

Specified by:
addArrayHolder in interface SessionImplementor

getSnapshot

public Serializable getSnapshot(PersistentCollection coll)
Description copied from interface: SessionImplementor
Get the snapshot of the pre-flush collection state

Specified by:
getSnapshot in interface SessionImplementor

getLoadedCollectionKey

public Serializable getLoadedCollectionKey(PersistentCollection coll)
Description copied from interface: SessionImplementor
Get the pre-flush identifier of the collection

Specified by:
getLoadedCollectionKey in interface SessionImplementor

isInverseCollection

public boolean isInverseCollection(PersistentCollection collection)
Description copied from interface: SessionImplementor
Is this the "inverse" end of a bidirectional association?

Specified by:
isInverseCollection in interface SessionImplementor

getOrphans

public Collection getOrphans(PersistentCollection coll)
                      throws HibernateException
Description copied from interface: SessionImplementor
Get the collection orphans (entities which were removed from the collection)

Specified by:
getOrphans in interface SessionImplementor
Throws:
HibernateException

initializeCollection

public void initializeCollection(PersistentCollection collection,
                                 boolean writing)
                          throws HibernateException
called by a collection that wants to initialize itself

Specified by:
initializeCollection in interface SessionImplementor
Throws:
HibernateException

getCollectionOwner

public Object getCollectionOwner(Serializable key,
                                 CollectionPersister collectionPersister)
                          throws MappingException
Specified by:
getCollectionOwner in interface SessionImplementor
Throws:
MappingException

connection

public Connection connection()
                      throws HibernateException
Description copied from interface: Session
Get the JDBC connection. Applications are responsible for calling commit/rollback upon the connection before closing the Session.

Specified by:
connection in interface Session
Returns:
the JDBC connection in use by the Session
Throws:
HibernateException - if the Session is disconnected

isConnected

public boolean isConnected()
Description copied from interface: Session
Check if the Session is currently connected.

Specified by:
isConnected in interface Session
Returns:
boolean

disconnect

public Connection disconnect()
                      throws HibernateException
Description copied from interface: Session
Disconnect the Session from the current JDBC connection. If the connection was obtained by Hibernate, close it or return it to the connection pool. Otherwise return it to the application.

This is used by applications which require long transactions.

Specified by:
disconnect in interface Session
Returns:
the connection provided by the application or null
Throws:
HibernateException - if the Session is disconnected
See Also:
Session.reconnect()

reconnect

public void reconnect()
               throws HibernateException
Description copied from interface: Session
Obtain a new JDBC connection. This is used by applications which require long transactions.

Specified by:
reconnect in interface Session
Throws:
HibernateException
See Also:
Session.disconnect()

reconnect

public void reconnect(Connection conn)
               throws HibernateException
Description copied from interface: Session
Reconnect to the given JDBC connection. This is used by applications which require long transactions.

Specified by:
reconnect in interface Session
Parameters:
conn - a JDBC connection
Throws:
HibernateException - if the Session is connected
See Also:
Session.disconnect()

finalize

protected void finalize()
                 throws Throwable
Just in case user forgot to commit()/cancel() or close()

Throws:
Throwable

filter

public Collection filter(Object collection,
                         String filter)
                  throws HibernateException
Description copied from interface: Session
Apply a filter to a persistent collection. A filter is a Hibernate query that may refer to this, the collection element. Filters allow efficient access to very large lazy collections. (Executing the filter does not initialize the collection.)

Specified by:
filter in interface Session
Parameters:
collection - a persistent collection to filter
filter - a filter query string
Returns:
Collection the resulting collection
Throws:
HibernateException

filter

public Collection filter(Object collection,
                         String filter,
                         Object value,
                         Type type)
                  throws HibernateException
Description copied from interface: Session
Apply a filter to a persistent collection. A filter is a Hibernate query that may refer to this, the collection element.

Specified by:
filter in interface Session
Parameters:
collection - a persistent collection to filter
filter - a filter query string
value - a value to be witten to a "?" placeholder in the query string
type - the hibernate type of value
Returns:
Collection
Throws:
HibernateException

filter

public Collection filter(Object collection,
                         String filter,
                         Object[] values,
                         Type[] types)
                  throws HibernateException
Description copied from interface: Session
Apply a filter to a persistent collection. Bind the given parameters to "?" placeholders. A filter is a Hibernate query that may refer to this, the collection element.

Specified by:
filter in interface Session
Parameters:
collection - a persistent collection to filter
filter - a filter query string
values - a list of values to be written to "?" placeholders in the query
types - a list of Hibernate types of the values
Returns:
Collection
Throws:
HibernateException

filter

public List filter(Object collection,
                   String filter,
                   QueryParameters queryParameters)
            throws HibernateException
Description copied from interface: SessionImplementor
Execute a filter

Specified by:
filter in interface SessionImplementor
Throws:
HibernateException

iterateFilter

public Iterator iterateFilter(Object collection,
                              String filter,
                              QueryParameters queryParameters)
                       throws HibernateException
Description copied from interface: SessionImplementor
Iterate a filter

Specified by:
iterateFilter in interface SessionImplementor
Throws:
HibernateException

createCriteria

public Criteria createCriteria(Class persistentClass)
Description copied from interface: Session
Create a new Criteria instance, for the given entity class.

Specified by:
createCriteria in interface Session
Parameters:
persistentClass -
Returns:
Criteria

find

public List find(CriteriaImpl criteria)
          throws HibernateException
Throws:
HibernateException

contains

public boolean contains(Object object)
Description copied from interface: Session
Check if this instance is associated with this Session.

Specified by:
contains in interface Session
Parameters:
object - an instance of a persistent class
Returns:
true if the given instance is associated with this Session

evict

public void evict(Object object)
           throws HibernateException
remove any hard references to the entity that are held by the infrastructure (references held by application or other persistant instances are okay)

Specified by:
evict in interface Session
Parameters:
object - a persistent instance
Throws:
HibernateException

getVersion

public Object getVersion(Object entity)
Description copied from interface: SessionImplementor
Get the current versioon of the entity

Specified by:
getVersion in interface SessionImplementor

getCollectionBatch

public Serializable[] getCollectionBatch(CollectionPersister collectionPersister,
                                         Serializable id,
                                         int batchSize)
Description copied from interface: SessionImplementor
Get a batch of uninitialized collection keys for this role

Specified by:
getCollectionBatch in interface SessionImplementor
Parameters:
collectionPersister - the collection role
id - a key that must be included
batchSize - the maximum number of keys to return
Returns:
an array of collection keys, of length batchSize (padded with nulls)

getClassBatch

public Serializable[] getClassBatch(Class clazz,
                                    Serializable id,
                                    int batchSize)
Description copied from interface: SessionImplementor
Get a batch of unloaded identifiers for this class

Specified by:
getClassBatch in interface SessionImplementor
Parameters:
clazz - the persistent class
id - an identifier that must be included
batchSize - the maximum number of keys to return
Returns:
an array of identifiers, of length batchSize (padded with nulls)

scheduleBatchLoad

public void scheduleBatchLoad(Class clazz,
                              Serializable id)
                       throws MappingException
Description copied from interface: SessionImplementor
Register the entity as batch loadable, if enabled

Specified by:
scheduleBatchLoad in interface SessionImplementor
Throws:
MappingException

createSQLQuery

public Query createSQLQuery(String sql,
                            String returnAlias,
                            Class returnClass)
Description copied from interface: Session
Create a new instance of Query for the given SQL string.

Specified by:
createSQLQuery in interface Session
Parameters:
sql - a query expressed in SQL
returnAlias - a table alias that appears inside {} in the SQL string
returnClass - the returned persistent class

createSQLQuery

public Query createSQLQuery(String sql,
                            String[] returnAliases,
                            Class[] returnClasses)
Description copied from interface: Session
Create a new instance of Query for the given SQL string.

Specified by:
createSQLQuery in interface Session
Parameters:
sql - a query expressed in SQL
returnAliases - an array of table aliases that appear inside {} in the SQL string
returnClasses - the returned persistent classes

createSQLQuery

public Query createSQLQuery(String sql,
                            String[] returnAliases,
                            Class[] returnClasses,
                            Collection querySpaces)

findBySQL

public List findBySQL(String sqlQuery,
                      String[] aliases,
                      Class[] classes,
                      QueryParameters queryParameters,
                      Collection querySpaces)
               throws HibernateException
Description copied from interface: SessionImplementor
Execute an SQL Query

Specified by:
findBySQL in interface SessionImplementor
Throws:
HibernateException

clear

public void clear()
Description copied from interface: Session
Completely clear the session. Evict all loaded instances and cancel all pending saves, updates and deletions. Do not close open iterators or instances of ScrollableResults.

Specified by:
clear in interface Session

loadByUniqueKey

public Object loadByUniqueKey(Class clazz,
                              String uniqueKeyPropertyName,
                              Serializable id)
                       throws HibernateException
Description copied from interface: SessionImplementor
Load an instance by a unique key that is not the primary key.

Specified by:
loadByUniqueKey in interface SessionImplementor
Throws:
HibernateException

replicate

public void replicate(Object obj,
                      ReplicationMode replicationMode)
               throws HibernateException
Description copied from interface: Session
Persist all reachable transient objects, reusing the current identifier values. Note that this will not trigger the Interceptor of the Session.

Specified by:
replicate in interface Session
Parameters:
obj - a transient instance of a persistent class
Throws:
HibernateException

getSessionFactory

public SessionFactory getSessionFactory()
Description copied from interface: Session
Get the SessionFactory that created this instance.

Specified by:
getSessionFactory in interface Session
See Also:
SessionFactory

getCollection

public Object getCollection(String role,
                            Serializable id,
                            Object owner)
                     throws HibernateException
instantiate a collection wrapper (called when loading an object)

Specified by:
getCollection in interface SessionImplementor
Throws:
HibernateException

cancelQuery

public void cancelQuery()
                 throws HibernateException
Description copied from interface: Session
Cancel execution of the current query. May be called from one thread to stop execution of a query in another thread. Use with care!

Specified by:
cancelQuery in interface Session
Throws:
HibernateException

addNonExist

public void addNonExist(Key key)
Specified by:
addNonExist in interface SessionImplementor

saveOrUpdateCopy

public Object saveOrUpdateCopy(Object object)
                        throws HibernateException
Description copied from interface: Session
Copy the state of the given object onto the persistent object with the same identifier. If there is no persistent instance currently associated with the session, it will be loaded. Return the persistent instance. If the given instance is unsaved or does not exist in the database, save it and return it as a newly persistent instance. Otherwise, the given instance does not become associated with the session.

Specified by:
saveOrUpdateCopy in interface Session
Parameters:
object - a transient instance with state to be copied
Returns:
an updated persistent instance
Throws:
HibernateException

copy

public Object copy(Object object,
                   Map copiedAlready)
            throws HibernateException
Specified by:
copy in interface SessionImplementor
Throws:
HibernateException

doCopy

public Object doCopy(Object object,
                     Serializable id,
                     Map copiedAlready)
              throws HibernateException
Throws:
HibernateException

saveOrUpdateCopy

public Object saveOrUpdateCopy(Object object,
                               Serializable id)
                        throws HibernateException
Description copied from interface: Session
Copy the state of the given object onto the persistent object with the given identifier. If there is no persistent instance currently associated with the session, it will be loaded. Return the persistent instance. If there is no database row with the given identifier, save the given instance and return it as a newly persistent instance. Otherwise, the given instance does not become associated with the session.

Specified by:
saveOrUpdateCopy in interface Session
Parameters:
object - a persistent or transient instance with state to be copied
id - the identifier of the instance to copy to
Returns:
an updated persistent instance
Throws:
HibernateException

convert

protected JDBCException convert(SQLException sqlException,
                                String message)