本文整理了Java中javax.transaction.Transaction.commit()
方法的一些代码示例,展示了Transaction.commit()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Transaction.commit()
方法的具体详情如下:
包路径:javax.transaction.Transaction
类名称:Transaction
方法名:commit
[英]Attempt to commit this transaction.
[中]尝试提交此事务。
代码示例来源:origin: spring-projects/spring-framework
public void endTransaction() throws Exception {
if (this.transaction != null) {
try {
if (this.rollbackOnly) {
this.transaction.rollback();
}
else {
this.transaction.commit();
}
}
finally {
this.transaction = null;
this.rollbackOnly = false;
}
}
}
}
代码示例来源:origin: stackoverflow.com
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();
}
代码示例来源:origin: stackoverflow.com
public void create(T entity) {
Session session=getSessionFactory().getCurrentSession();
Transaction trans=session.beginTransaction();
session.save(entity);
trans.commit();
}
代码示例来源:origin: stackoverflow.com
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();
}
代码示例来源:origin: stackoverflow.com
Session session = sessionFactory.openSession();
Transaction transaction = session.beginTransaction();
User userA = (User)session.get(User.class, 1101);
transaction.commit();
session.close();
// Since session is closed, userA is detached.
session = sessionFactory.openSession();
transaction = session.beginTransaction();
User userB = (User)session.get(User.class, 1101);
//Now here, userB represents the same persistent row as userA.
//When an attempt to reattach userA occurs, an exception is thrown
session.update(userA);
transaction.commit();
session.close();
代码示例来源:origin: stackoverflow.com
Session session = factory.openSession();
Transaction tx = null;
try {
tx = session.beginTransaction();
...
tx.commit();
}
catch (Exception e) {
if (tx!=null) tx.rollback();
}finally {
session.close();
}
代码示例来源:origin: stackoverflow.com
Session session = sessionFactory.openSession();
Transaction transaction = session.beginTransaction();
User userA = (User)session.get(User.class, 1101);
transaction.commit();
session.close();
//userA is now detached as session is closed.
session = sessionFactory.openSession();
transaction = session.beginTransaction();
User userB = (User)session.get(User.class, 1101);
User userC = (User)session.merge(userA);
if (userB == userC) {
System.out.println("Reattched user is equal");
}
transaction.commit();
session.close();
代码示例来源:origin: stackoverflow.com
public void addUser(User user) {
try{
Session session = sessionFactory.getCurrentSession();
Transaction trans = session.beginTransaction();
session.save(user);
trans.commit();
}catch(Exception e){
trans.rollback();
}
}
代码示例来源:origin: stackoverflow.com
Session session = factory.getCurrentSession();
Transaction tx = session.beginTransaction();
Product p = new Product();
session.persist(p);
session.flush();
System.out.println(session.isOpen()); // prints true
p.setName("foo");
session.merge(p);
tx.commit();
System.out.println(session.isOpen()); // prints false
代码示例来源:origin: org.springframework/spring-tx
public void endTransaction() throws Exception {
if (this.transaction != null) {
try {
if (this.rollbackOnly) {
this.transaction.rollback();
}
else {
this.transaction.commit();
}
}
finally {
this.transaction = null;
this.rollbackOnly = false;
}
}
}
}
代码示例来源:origin: stackoverflow.com
try {
Session session = factory.openSession();
Transaction tx = session.beginTransaction();
...
tx.commit();
session.close();
} catch (SomeException e) {
tx.rollback();
...
}
代码示例来源:origin: stackoverflow.com
Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();
for ( int i=0; i<888888; i++ ) {
TableA record = new TableA();
record.setXXXX();
session.save(record)
if ( i % 50 == 0 ) { //50, same as the JDBC batch size
//flush a batch of inserts and release memory:
session.flush();
session.clear();
}
}
tx.commit();
session.close();
代码示例来源:origin: wildfly/wildfly
@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);
}
}
}
代码示例来源:origin: stackoverflow.com
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();
}
代码示例来源:origin: stackoverflow.com
Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();
for ( int i=0; i<100000; i++ ) {
Customer customer = new Customer(.....);
session.save(customer);
if ( i % 20 == 0 ) { //20, same as the JDBC batch size
//flush a batch of inserts and release memory:
session.flush();
session.clear();
}
}
tx.commit();
session.close();
代码示例来源:origin: stackoverflow.com
try {
Transaction t = sessionFactory.getCurrentSession().beginTransaction();
try {
// do work
t.commit();
} catch (Exception e) {
t.rollback();
throw e;
}
} finally {
sessionFactory.getCurrentSession().close();
}
代码示例来源:origin: stackoverflow.com
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();
}
代码示例来源:origin: stackoverflow.com
Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();
for ( int i=0; i<100000; i++ ) {
Customer customer = new Customer(.....);
session.save(customer);
if ( i % 20 == 0 ) { //20, same as the JDBC batch size
//flush a batch of inserts and release memory:
session.flush();
session.clear();
}
}
tx.commit();
session.close();
代码示例来源:origin: stackoverflow.com
Transaction tx = null;
try {
tx = session.beginTransaction()
Profesor p2 = (Profesor) session.merge(p);
session.saveOrUpdate(p2);
tx.commit();
} catch(Exception e) {
tx.rollback();
}
代码示例来源:origin: stackoverflow.com
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();
}
内容来源于网络,如有侵权,请联系作者删除!