从Hibernate参考手册中:
“数据库事务绝不是可选的,与数据库的所有通信都必须在事务内部进行,无论您是读还是写数据”
我建议您将所有持久性操作都包含在事务中。例如。
Session session = factory.openSession();Transaction tx;try { tx = session.beginTransaction(); session.save(object); tx.commit();}catch (Exception e) { if (tx != null) tx.rollback(); throw e;}finally { session.close();}


