Refine search
final Session session = HibernateUtil.getSession(); try { final Transaction transaction = session.beginTransaction(); try { // The real work is here transaction.commit(); } catch (Exception ex) { // Log the exception here transaction.rollback(); throw ex; } } finally { HibernatilUtil.closeSession(); }
Session s = null; Transaction t = null; try { s = getSessionFactory().openSession(); t = s.beginTransaction(); // code to persist the object } catch(HibernateException he) { if(t != null) { t.rollback(); } } finally { if(s != null) { s.close(); } }
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(); }
public List<Foo> getFoo(long id) { Session session = HibernateUtil.getSessionFactory().getCurrentSession(); List<Foo> feeds = null; try { Transaction tx=session.beginTransaction(); feeds = (List<Foo>) session.createQuery( "from Foo as foo " +"left join foo.bar as bar " +"where bar.id=:id") .setParameter("id", id) .list(); }Catch(HibernateException e){ System.out.println("Exception "+e); if(tx!=null){ tx.rollback(); } }
Session session = factory.openSession(); Transaction tx = null; try { tx = session.beginTransaction(); ... tx.commit(); } catch (Exception e) { if (tx!=null) tx.rollback(); }finally { session.close(); }
public List getSelectList(String query) throws Exception { Session session = sessionFactory.createSession(); try { session.beginTransaction(); List list = session.createQuery(query).list(); session.getTransaction().commit(); return list ; } catch (Exception e) { Transaction tx = session.getTransaction(); if (tx != null) { tx.rollback(); } throw e ; } }
@Override public void close() { if (this.count.getAndDecrement() == 0) { try { switch (this.tx.getStatus()) { case Status.STATUS_ACTIVE: { if (this.active) { try { this.tx.commit(); break; } catch (RollbackException e) { throw new IllegalStateException(e); } catch (HeuristicMixedException | HeuristicRollbackException e) { throw new CacheException(e); } } // Otherwise fall through } case Status.STATUS_MARKED_ROLLBACK: { this.tx.rollback(); break; } } } catch (SystemException e) { throw new CacheException(e); } } }
try { Session session = factory.openSession(); Transaction tx = session.beginTransaction(); ... tx.commit(); session.close(); } catch (SomeException e) { tx.rollback(); ... }
public void removeChild(Parent parent, Child child) { Session session = HibernateUtil.getSessionFactory().openSession(); Transaction tx = null; try { session.beginTransaction(); parent.getChildren().remove(child); session.delete(child); session.getTransaction().commit(); // session.refresh(parent); // this is not required } catch (RuntimeException e) { if (tx != null) { tx.rollback(); } throw e; } finally { session.close(); } }
public void addUser(User user) { try{ Session session = sessionFactory.getCurrentSession(); Transaction trans = session.beginTransaction(); session.save(user); trans.commit(); }catch(Exception e){ trans.rollback(); } }
Session s = sessionfactory.openSession(); Transaction tx = null; try { tx = s.beginTransaction(); // Your data manipulation here tx.commit(); } catch (Exception e) { if (tx != null) { tx.rollback();} } finally { s.close(); }
Session sess = factory.openSession(); Transaction tx = null; try { tx = sess.beginTransaction(); //do some work, point 3 tx.commit(); } catch (Exception e) { if (tx!=null) tx.rollback(); throw e; } finally { sess.close(); }
Session session = sessionFactory.openSession(); Transaction transaction = session.beginTransaction(); try { // do something transaction.commit(); } catch (Exception ex) { // on error, revert changes made on DB if (transaction != null) { transaction.rollback(); } } finally { session.close(); }