/** {@inheritDoc} */ @Override public void txEnd(GridCacheTx tx, boolean commit) throws GridException { init(); Session ses = tx.removeMeta(ATTR_SES); if (ses != null) { Transaction hTx = ses.getTransaction(); if (hTx != null) { try { if (commit) { ses.flush(); hTx.commit(); } else hTx.rollback(); if (log.isDebugEnabled()) log.debug("Transaction ended [xid=" + tx.xid() + ", commit=" + commit + ']'); } catch (HibernateException e) { throw new GridException( "Failed to end transaction [xid=" + tx.xid() + ", commit=" + commit + ']', e); } finally { ses.close(); } } } }
/** * Rolls back hibernate session. * * @param ses Hibernate session. * @param tx Cache ongoing transaction. */ private void rollback(SharedSessionContract ses, GridCacheTx tx) { // Rollback only if there is no cache transaction, // otherwise txEnd() will do all required work. if (tx == null) { Transaction hTx = ses.getTransaction(); if (hTx != null && hTx.isActive()) hTx.rollback(); } }
/** * Ends hibernate session. * * @param ses Hibernate session. * @param tx Cache ongoing transaction. */ private void end(Session ses, GridCacheTx tx) { // Commit only if there is no cache transaction, // otherwise txEnd() will do all required work. if (tx == null) { Transaction hTx = ses.getTransaction(); if (hTx != null && hTx.isActive()) hTx.commit(); ses.close(); } }
public static void rollback(Transaction tx) { try { if (tx != null) { tx.rollback(); } } catch (HibernateException e) { System.out.println(e); } }
public static void main(String[] args) { Configuration cfg = new Configuration(); cfg = cfg.configure("hibernate.oracle.cfg.xml"); SessionFactory factory = cfg.buildSessionFactory(); Session ses = factory.openSession(); Bank b = new Bank(); String name; name = "SBI"; // b.setSid(sid); b.setName(name); Transaction tx = ses.beginTransaction(); ses.persist(b); tx.commit(); ses.close(); System.out.println("Record Inserted!"); factory.close(); }
/** {@inheritDoc} */ @Override public void onSessionEnd(CacheStoreSession ses, boolean commit) { Session hibSes = ses.attach(null); if (hibSes != null) { try { Transaction tx = hibSes.getTransaction(); if (commit) { hibSes.flush(); if (tx.isActive()) tx.commit(); } else if (tx.isActive()) tx.rollback(); } catch (HibernateException e) { throw new CacheWriterException( "Failed to end store session [tx=" + ses.transaction() + ']', e); } finally { hibSes.close(); } } }