Java Reference
In-Depth Information
// Normal usage of the Session here...
Publisher p = new Publisher(username);
Subscriber s = new Subscriber(username);
session.saveOrUpdate(p);
session.saveOrUpdate(s);
// Commit the transaction
session.getTransaction().commit();
} catch (HibernateException e1) {
rollback(session);
throw e1;
} finally {
// Close the session
close(session);
}
}
public static void reset(Session session, int isolation) {
if (isolation >= 0) {
try {
session.connection().setTransactionIsolation(isolation);
} catch (SQLException e) {
System.err.println("Could not reset the isolation level: " + e);
} catch (HibernateException e) {
System.err.println("Could not reset the isolation level: " + e);
}
}
}
public static void close(Session session) {
try {
session.close();
} catch (HibernateException e) {
System.err.println("Could not close the session: " + e);
}
}
public static void rollback(Session session) {
try {
Transaction tx = session.getTransaction();
if (tx.isActive())
tx.rollback();
} catch (HibernateException e) {
System.err.println("Could not rollback the session: " + e);
}
}
Search WWH ::




Custom Search