Here are the examples of the java api net.sf.hibernate.Session taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
1 Examples
5
Source : ScheduledMetricEvaluatorImpl.java
with BSD 2-Clause "Simplified" License
from AndreyVMarkelov
with BSD 2-Clause "Simplified" License
from AndreyVMarkelov
private void calculateTotalAttachmentSize() {
Session session = null;
Transaction transaction = null;
try {
session = sessionFactory.openSession();
transaction = session.beginTransaction();
try (Statement statement = session.connection().createStatement()) {
try (ResultSet rs = statement.executeQuery(ATTACHMENT_SQL)) {
if (rs.next()) {
Long value = rs.getLong(1);
if (rs.wasNull() && MISSED_ATTACHMENT_TABLE_VERSION.compareTo(GeneralUtil.getVersionNumber()) > 0) {
try (ResultSet rs2 = statement.executeQuery(ATTACHMENT_SQL_OLD)) {
if (rs2.next()) {
totalAttachmentSize.set(rs2.getLong(1));
}
}
} else {
totalAttachmentSize.set(value);
}
}
}
try (ResultSet rs = statement.executeQuery(PAGE_SQL)) {
if (rs.next()) {
totalPages.set(rs.getInt(1));
}
}
try (ResultSet rs = statement.executeQuery(BLOGPOST_SQL)) {
if (rs.next()) {
totalBlogPosts.set(rs.getInt(1));
}
}
}
} catch (Throwable th) {
if (transaction != null) {
try {
transaction.rollback();
} catch (HibernateException ex) {
log.error("Cannot rollback hibernate transaction", ex);
}
}
log.error("Error execute SQL", th);
} finally {
if (transaction != null) {
try {
transaction.commit();
} catch (HibernateException ex) {
log.error("Error commit hibernate transaction", ex);
}
}
if (session != null) {
try {
session.close();
} catch (HibernateException ex) {
log.error("Cannot close hibernate session", ex);
}
}
}
}