在项目中配置了两个数据源 然后在从一个数据库读出来数据存到另外一个数据库的时候, 报-Transaction not successfully started这个异常,
代码:
Session session = this.screenStaticDao.getCurrentSession();
Transaction tran =session.beginTransaction();
pojo.setChannelName(vo.getCHANNEL_NAME());
pojo.setDailyViewingTime(vo.getDAILY_VIEWING_TIME());
pojo.setAnalysisDate(vo.getANALYSIS_DATE());
pojo.setRegionName(provinceName);
this.screenStaticDao.insertData(pojo);
tran.commit();
修改为:
Session session = this.screenStaticDao.getCurrentSession();
pojo.setChannelName(vo.getCHANNEL_NAME());
pojo.setDailyViewingTime(vo.getDAILY_VIEWING_TIME());
pojo.setAnalysisDate(vo.getANALYSIS_DATE());
pojo.setRegionName(provinceName);
this.screenStaticDao.insertData(pojo);
session.flush();
session.clear();;