我有一个问题。
我有这个功能:
public boolean insertOrgToAlign(OrganizationData orgData) {
try {
if (eManager.find(ScOrgNotAligned.class, orgData.getOrganizationCode()) == null) {
ScAdminGroup rootByOrg = null;
AdminGroupBean admGrp = null;
try {
rootByOrg = adminGroupServices.getRootAdminGroupByOrg(orgData.getOrganizationCode());
} catch (NoResultException e) {
logger.debugT("insertOrgToAlign(..) - org to align has no root");
return false;
} catch (NonUniqueResultException e) {
logger.debugT("insertOrgToAlign(..) - org to align has more than one root");
admGrp = new AdminGroupBean();
admGrp.setAdmGroupId(-1);
admGrp.setAdmGroupName("ERROR");
ScOrgNotAligned scOrgNotAlig = new ScOrgNotAligned(orgData, admGrp);
eManager.persist(scOrgNotAlig);
logger.debugT("insertOrgToAlign(..) - persist org to adjust manually : "
+ orgData.getOrganizationName());
return true;
}
admGrp = new AdminGroupBean(rootByOrg);
ScOrgNotAligned scOrgNotAlig = new ScOrgNotAligned(orgData, admGrp);
//**************************
//THIS IS THE WRONG LINE????
eManager.persist(scOrgNotAlig);
//**************************
logger.debugT("insertOrgToAlign(..) - persist org to align : " + orgData.getOrganizationName());
} else {
logger.debugT("insertOrgToAlign(..) - org to align already exists in db : "
+ orgData.getOrganizationName());
}
} catch (Exception e) {
logger.traceThrowableT(Severity.ERROR, e.getMessage(), e);
return false;
}
return true;
}
如果我评论 eManager.persist(scOrgNotAlig); 行,则该函数在DB中写入权限;如果我取消注释该行,该函数会在它写入数据库时导致回滚。
异常的堆栈跟踪是:
(Failed in component: sap.com/tc~ejbexplorer~ear, BC-JAS-EJB) nested exception is:
com.sap.engine.services.ts.exceptions.BaseRollbackException: Exception in
beforeCompletion of ( JTA Transaction : 45491 ).
为什么呢?有什么想法吗?