在我们将应用程序从 hibernate3 迁移到 hibernate4 之前的一周,在 hibernate3 中一切正常,但是在迁移到 hibernate4 之后。我不断收到不支持的嵌套事务。
下面是我调用 dao 的服务层
public class LeaveApplicationService implementsSerializable,LeaveApplicationInterfaceService{
@Autowired
private LeaveApplicationInterfaceDao _leavApplicationInterfaceDao;
//getter setter
@Override
public synchronized void clickOnAddLeaveButton(LeaveApplicationViewBean leaveApplicationViewBean) {
SessionFactory sessionFactory=(SessionFactory) ObjectFactory.getBean("sessionFactory");
sessionFactory.getCurrentSession().beginTransaction();
try{
leaveApplicationViewBean.get_employeeListObj().clear();
leaveApplicationViewBean.get_leaveTypelist().clear();
leaveApplicationViewBean.get_leaveApproveers().clear();
//leaveApplicationViewBean.set_employeeListObj(get_leavApplicationInterfaceDao().getEmployeeList());
leaveApplicationViewBean.set_leaveTypelist(get_leavApplicationInterfaceDao().getLeaveType());
leaveApplicationViewBean.set_leaveApproveers(get_leavApplicationInterfaceDao().getLeaveApprover(CmsUtil.getSession("userId").toString()));
}catch(Exception e){
CmsLogger.errorLog(LeaveApplicationService.class, e);
}finally{
sessionFactory.getCurrentSession().close();
}
}
道层
public class LeaveApplicationDao extends TransactionService implements Serializable,LeaveApplicationInterfaceDao{
private static final long serialVersionUID = 6237725881698448330L;
public List<LeaveApprover> getLeaveApprover(String userId) throws Exception {
List<LeaveApprover> _leavApprovers=new ArrayList<LeaveApprover>();
Iterator it=getSessionFactory().getCurrentSession().createQuery(sql.toString()).setParameter("practiceAreaId",CmsUtil.getSession("practiceAreaId").toString()) .setParameter("userId",userId).setCacheable(true)
.list().iterator();
while(it.hasNext()){
Object[] obj=(Object[]) it.next();
LeaveApprover leaveApprover=new LeaveApprover();
leaveApprover.set_approverId((String) obj[0]);
leaveApprover.set_approverName((String) obj[1]);
_leavApprovers.add(leaveApprover);
}
return _leavApprovers;
}
public List<TimeProjectCategory> getLeaveType() throws Exception{
List<TimeProjectCategory> timeProjectCategories=new ArrayList<TimeProjectCategory>();
Iterator it =getSessionFactory().getCurrentSession().createQuery(sql.toString()).setCacheable(true).list().iterator();
while(it.hasNext()){
Object[] obj=(Object[]) it.next();
TimeProjectCategory category=(TimeProjectCategory) ObjectFactory.getBean("domainTimeProjectCategoryObj");
category.getProjectId().set_projectId((String) obj[0]);
category.setTimeCategory((String) obj[1]);
category.setTimeProjectCategoryId((String) obj[2]);
timeProjectCategories.add(category);
}
return timeProjectCategories;
}
}
还有我的 TransactionService 类
public class TransactionService{
/**
*
*/
private static final long serialVersionUID = 3747504246445270484L;
@Autowired
private DataSource dataSource;
@Autowired
private SessionFactory sessionFactory;
public SessionFactory getSessionFactory() {
return sessionFactory;
}
public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}
public DataSource getDataSource() {
return dataSource;
}
public void setDataSource(DataSource dataSource) {
this.dataSource = dataSource;
}
}
我在堆栈跟踪中看到的异常是
我的 db.xml