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();
}
| Method Summary | |
|---|---|
| Transaction |
Begin a unit of work and return the associated Transaction object. |
| void |
Cancel execution of the current query. |
| void |
Completely clear the session. |
| Connection |
End the Session by disconnecting from the JDBC connection and cleaning up. |
| Connection |
Get the JDBC connection of this Session. If the session is using aggressive collection release (as in a CMT environment), it is the application's responsibility to close the connection returned by this call. |
| boolean |
Check if this instance is associated with this Session. |
| Criteria |
Create a new Criteria instance, for the given entity class, or a superclass of an entity class. |
| Criteria |
Create a new Criteria instance, for the given entity class, or a superclass of an entity class, with the given alias. |
| Criteria |
Create a new Criteria instance, for the given entity name. |
| Criteria |
Create a new Criteria instance, for the given entity name, with the given alias. |
| Query |
Create a new instance of Query for the given collection and filter string. |
| Query |
Create a new instance of Query for the given HQL query string. |
| SQLQuery |
Create a new instance of SQLQuery for the given SQL query string. |
| void |
Remove a persistent instance from the datastore. |
| void |
Remove a persistent instance from the datastore. |
| void |
Disable the named filter for the current session. |
| Connection |
Disconnect the Session from the current JDBC connection. |
| Filter |
Enable the named filter for this current session. |
| void |
Remove this instance from the session cache. |
| void |
Force the Session to flush. |
| Object |
Return the persistent instance of the given entity class with the given identifier, or null if there is no such persistent instance. |
| Object |
Return the persistent instance of the given entity class with the given identifier, or null if there is no such persistent instance. |
| Object |
Return the persistent instance of the given named entity with the given identifier, or null if there is no such persistent instance. |
| Object |
Return the persistent instance of the given entity class with the given identifier, or null if there is no such persistent instance. |
| CacheMode |
Get the current cache mode. |
| LockMode |
Determine the current lock mode of the given object. |
| Filter |
Retrieve a currently enabled filter by name. |
| EntityMode |
Retrieve the entity mode in effect for this session. |
| String |
Return the entity name for a persistent entity |
| FlushMode |
Get the current flush mode. |
| Serializable |
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. |
| Query |
Obtain an instance of Query for a named query string defined in the mapping file. |
| Session |
Starts a new Session with the given entity mode in effect. |
| SessionFactory |
Get the SessionFactory that created this instance. |
| SessionStatistics |
Get the statistics for this session. |
| Transaction |
Get the Transaction instance associated with this session. |
| boolean |
Check if the Session is currently connected. |
| boolean |
Does this Session contain any changes which must be synchronized with the database? Would any SQL be executed if we flushed this session? |
| boolean |
Check if the Session is still open. |
| Object |
Return the persistent instance of the given entity class with the given identifier, obtaining the specified lock mode, assuming the instance exists. |
| Object |
Return the persistent instance of the given entity class with the given identifier, obtaining the specified lock mode, assuming the instance exists. |
| Object |
Return the persistent instance of the given entity class with the given identifier, assuming that the instance exists. |
| Object |
Return the persistent instance of the given entity class with the given identifier, assuming that the instance exists. |
| void |
Read the persistent state associated with the given identifier into the given transient instance. |
| void |
Obtain the specified lock level upon the given object. |
| void |
Obtain the specified lock level upon the given object. |
| Object |
Copy the state of the given object onto the persistent object with the same identifier. |
| Object |
Copy the state of the given object onto the persistent object with the same identifier. |
| void |
Make a transient instance persistent. |
| void |
Make a transient instance persistent. |
| void |
Obtain a new JDBC connection. |
| void |
Reconnect to the given JDBC connection. |
| void |
Re-read the state of the given instance from the underlying database. |
| void |
Re-read the state of the given instance from the underlying database, with the given LockMode. |
| void |
Persist the state of the given detached instance, reusing the current identifier value. |
| void |
Persist the state of the given detached instance, reusing the current identifier value. |
| Serializable |
Persist the given transient instance, first assigning a generated identifier. |
| Serializable |
Persist the given transient instance, first assigning a generated identifier. |
| void |
Either save() or update() the given instance, depending upon the value of its identifier property. |
| void |
Either save() or update() the given instance, depending upon the value of its identifier property. |
| void |
Set the cache mode. |
| void |
Set the flush mode. |
| void |
Set an unmodified persistent object to read only mode, or a read only object to modifiable mode. |
| void |
Update the persistent instance with the identifier of the given detached instance. |
| void |
Update the persistent instance with the identifier of the given detached instance. |
dsadasadasda
public
void
clear
(
)
public
boolean
isConnected
(
)