Session sess = factory.openSession();
Transaction tx;
try {
tx = sess.beginTransaction();
//do some work
...
tx.commit();
}
catch (Exception e) {
if (tx!=null) tx.rollback();
throw e;
}
finally {
sess.close();
}
SessionFactory
| Modifier and Type | Class and Description |
|---|---|
| public static interface | Session.LockRequest
Contains locking details (LockMode, Timeout and Scope). |
| Modifier and Type | Method and Description |
|---|---|
| public Transaction | Returns: a Transaction instanceBegin a unit of work and return the associated Transaction object. |
| public Session. | Returns: a lockRequest that can be used to lock the passed object.contains the lock level lockOptions)Build a LockRequest that specifies the LockMode, pessimistic lock timeout and lock scope. |
| public void | |
| public void | |
| public Connection | Returns: the connection provided by the application or null.End the session by releasing the JDBC connection and cleaning up. |
| public Connection | Returns: the JDBC connection in use by the Session
Deprecated
(scheduled for removal in 4.x).
Get the JDBC connection of this Session.
|
| public boolean | |
| public Criteria | Returns: Criteriaa class, which is persistent, or has persistent subclasses persistentClass)Create a new Criteria instance, for the given entity class, or a superclass of an entity class. |
| public Criteria | Returns: Criteriaa class, which is persistent, or has persistent subclasses persistentClass, String alias)Create a new Criteria instance, for the given entity class, or a superclass of an entity class, with the given alias. |
| public Criteria | Returns: CriteriaCreate a new Criteria instance, for the given entity name. |
| public Criteria | Returns: CriteriaCreate a new Criteria instance, for the given entity name, with the given alias. |
| public Query | Returns: Querya persistent collection collection, String a Hibernate query queryString)Create a new instance of Query for the given collection and filter string. |
| public Query | Returns: Querya HQL query queryString)Create a new instance of Query for the given HQL query string. |
| public SQLQuery | Returns: SQLQuerya SQL query queryString)Create a new instance of SQLQuery for the given SQL query string. |
| public void | |
| public void | |
| public void | disableFetchProfile(String
The name of the fetch profile to be disabled. name)Disable a particular fetch profile on this session. |
| public void | disableFilter(String
The name of the filter to be disabled. filterName)Disable the named filter for the current session. |
| public Connection | Returns: the application-supplied connection or nullDisconnect the Session from the current JDBC connection. |
| public void | |
| public void | enableFetchProfile(String
The name of the fetch profile to be enabled. name)Enable a particular fetch profile on this session. |
| public Filter | Returns: The Filter instance representing the enabled filter.The name of the filter to be enabled. filterName)Enable the named filter for this current session. |
| public void | |
| public void | |
| public Object | Returns: a persistent instance or nulla persistent class clazz, Serializable an identifier id)Return the persistent instance of the given entity class with the given identifier, or null if there is no such persistent instance. |
| public Object | Returns: a persistent instance or nulla persistent class clazz, Serializable an identifier id, LockMode the lock mode lockMode)
Deprecated
LockMode parameter should be replaced with LockOptions
Return the persistent instance of the given entity class with the given identifier,
or null if there is no such persistent instance.
|
| public Object | Returns: a persistent instance or nulla persistent class clazz, Serializable an identifier id, LockOptions the lock mode lockOptions)Return the persistent instance of the given entity class with the given identifier, or null if there is no such persistent instance. |
| public Object | Returns: a persistent instance or nullthe entity name entityName, Serializable an identifier id)Return the persistent instance of the given named entity with the given identifier, or null if there is no such persistent instance. |
| public Object | Returns: a persistent instance or nullthe entity name entityName, Serializable an identifier id, LockMode the lock mode lockMode)
Deprecated
LockMode parameter should be replaced with LockOptions
Return the persistent instance of the given entity class with the given identifier,
or null if there is no such persistent instance.
|
| public Object | Returns: a persistent instance or nullthe entity name entityName, Serializable an identifier id, LockOptions contains the lock mode lockOptions)Return the persistent instance of the given entity class with the given identifier, or null if there is no such persistent instance. |
| public CacheMode | |
| public LockMode | Returns: the current lock modea persistent instance object)Determine the current lock mode of the given object. |
| public Filter | Returns: The Filter instance representing the enabled filter.The name of the filter to be retrieved. filterName)Retrieve a currently enabled filter by name. |
| public EntityMode | Returns: The entity mode for this session.Retrieve the entity mode in effect for this session. |
| public String | Returns: the entity namea persistent entity object)Return the entity name for a persistent entity |
| public FlushMode | |
| public Serializable | Returns: the identifiera persistent instance object)Return the identifier value of the given entity as associated with this session. |
| public LobHelper | Returns: This session's LOB helperRetrieve this session's helper/delegate for creating LOB instances. |
| public Query | Returns: Querythe name of a query defined externally queryName)Obtain an instance of Query for a named query string defined in the mapping file. |
| public Session | Returns: The new sessionThe entity mode to use for the new session. entityMode)Starts a new Session with the given entity mode in effect. |
| public SessionFactory | |
| public SessionStatistics | |
| public Transaction | Returns: a Transaction instanceGet the Transaction instance associated with this session. |
| public TypeHelper | |
| public boolean | |
| public boolean | Returns: true, loaded entities/proxies will be made read-only by default; false, loaded entities/proxies will be made modifiable by default.Will entities and proxies that are loaded into this session be made read-only by default? |
| public boolean | Returns: True if the session contains pending changes; false otherwise.Does this session contain any changes which must be synchronized with the database? |
| public boolean | Returns: True if fetch profile is enabled; false if not.The name of the profile to be checked. name)Is a particular fetch profile enabled on this session? |
| public boolean | |
| public boolean | Returns: true, the entity or proxy is read-only; false, the entity or proxy is modifiable.an entity or HibernateProxy entityOrProxy)Is the specified entity or proxy read-only? |
| public Object | Returns: the persistent instance or proxya persistent class theClass, Serializable a valid identifier of an existing persistent instance of the class id, LockMode the lock level lockMode)
Deprecated
LockMode parameter should be replaced with LockOptions
Return the persistent instance of the given entity class with the given identifier,
obtaining the specified lock mode, assuming the instance exists.
|
| public Object | Returns: the persistent instance or proxya persistent class theClass, Serializable a valid identifier of an existing persistent instance of the class id, LockOptions contains the lock level lockOptions)Return the persistent instance of the given entity class with the given identifier, obtaining the specified lock mode, assuming the instance exists. |
| public Object | Returns: the persistent instance or proxya persistent class entityName, Serializable a valid identifier of an existing persistent instance of the class id, LockMode the lock level lockMode)
Deprecated
LockMode parameter should be replaced with LockOptions
Return the persistent instance of the given entity class with the given identifier,
obtaining the specified lock mode, assuming the instance exists.
|
| public Object | Returns: the persistent instance or proxya persistent class entityName, Serializable a valid identifier of an existing persistent instance of the class id, LockOptions contains the lock level lockOptions)Return the persistent instance of the given entity class with the given identifier, obtaining the specified lock mode, assuming the instance exists. |
| public Object | Returns: the persistent instance or proxya persistent class theClass, Serializable a valid identifier of an existing persistent instance of the class id)Return the persistent instance of the given entity class with the given identifier, assuming that the instance exists. |
| public Object | Returns: the persistent instance or proxya persistent class entityName, Serializable a valid identifier of an existing persistent instance of the class id)Return the persistent instance of the given entity class with the given identifier, assuming that the instance exists. |
| public void | load(Object
an "empty" instance of the persistent class object, Serializable a valid identifier of an existing persistent instance of the class id)Read the persistent state associated with the given identifier into the given transient instance. |
| public void | |
| public void | |
| public Object | |
| public Object | |
| public void | |
| public void | |
| public void | reconnect()
Deprecated
Manual reconnection is only needed in the case of
application-supplied connections, in which case the
Obtain a new JDBC connection.
reconnect(java. for should be used.
|
| public void | |
| public void | |
| public void | |
| public void | refresh(Object
a persistent or detached instance object, LockOptions contains the lock mode to use lockOptions)Re-read the state of the given instance from the underlying database, with the given LockMode. |
| public void | replicate(Object
a detached instance of a persistent class object, ReplicationMode replicationMode)Persist the state of the given detached instance, reusing the current identifier value. |
| public void | replicate(String entityName, Object
a detached instance of a persistent class object, ReplicationMode replicationMode)Persist the state of the given detached instance, reusing the current identifier value. |
| public Serializable | |
| public Serializable | |
| public void | saveOrUpdate(Object
a transient or detached instance containing new or updated state object)Either |
| public void | saveOrUpdate(String entityName, Object
a transient or detached instance containing new or updated state object)Either |
| public void | |
| public void | setDefaultReadOnly(boolean
true, the default for loaded entities/proxies is read-only;
false, the default for loaded entities/proxies is modifiable 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. |
| public void | |
| public void | setReadOnly(Object
an entity or HibernateProxy entityOrProxy, boolean if true, the entity or proxy is made read-only;
if false, the entity or proxy is made modifiable. readOnly)Set an unmodified persistent object to read-only mode, or a read-only object to modifiable mode. |
| public void | |
| public void |