hibernate 批处理不能正常提交 ,transatlantic not successfully started

事务今天弄了一下午,数据能正常提交但是,提交完了之后就是报错,后来终于找到原因希望对大家有所帮助

Session session=this.getSessionFactory().getCurrentSession();
   Transaction transation = session.beginTransaction();
   try {
    MesXtpzXcxtb obj=new MesXtpzXcxtb(object.getId()+"01","属性", sjbh,0L,1L, "属性",
      new Date(),xgr ,new Date(),xgr, 0);
    MesXtpzXcxtb obj1=new MesXtpzXcxtb(object.getId()+"02","监测点", sjbh,0L,2L, "监测点",
      new Date(),xgr ,new Date(),xgr, 0);
    MesXtpzXcxtb obj2=new MesXtpzXcxtb(object.getId()+"03","故障类型", sjbh,0L,3L, "故障类型",
      new Date(),xgr ,new Date(),xgr, 0);
    MesXtpzXcxtb obj3=new MesXtpzXcxtb(object.getId()+"04","运行信号", sjbh,0L,4L, "运行信号",
      new Date(),xgr ,new Date(),xgr, 0);
    session.save(object);
    session.save(obj);
    session.save(obj1);
    session.save(obj2);
    session.save(obj3);
          session.flush(); 
    -------------------------------------------//transation.commit();
   } catch (Exception e) {
   // TODO Auto-generated catch block
   flag=false;
   e.printStackTrace();
   transation.rollback();
  }
  finally
  {
   //session.close();
  }
   return flag
 ;

  -------------------------------------------//transation.commit();

关键点就在于红色部分,把commit 注释掉就好了,因为大多数的事务的配置在数据库中都配置好了,包括哪些方法名开头的事务。

相关推荐