【发布时间】:2015-03-13 13:34:06
【问题描述】:
这是我的代码的一部分。我正在使用 JTA 事务,这段代码抛出了唯一约束异常。
@TransactionAttribute( REQUIRED )
private int createProfileHelper(AccountBean accountInfo) throws Exception{
Long portfolio_customer_id = portfolioCustomerEntity.getId();
ExternalAccountEntity externalAccountEntity = new ExternalAccountEntity();
externalAccountEntity.setAccountNumber(accountInfo.getAccountNumber().toUpperCase());
externalAccountEntity.setBrand(brand);
externalAccountEntity.setAccountName(accountInfo.getAccountName());
externalAccountEntity.setRepId(accountInfo.getRepId());
externalAccountEntity.setCreatedBy(userName);
externalAccountEntity.setCreatedDate(new Date());
externalAccountEntity.setUserId(userId);
externalAccountEntity.setCustomerId(portfolio_customer_id); //join created between external account and portfolio_customer
persistenceToolsEntityManager.persist(externalAccountEntity);
}
我写了这段代码来处理异常:
public int createProfile(AccountBean accountInfo){
try{
return createProfileHelper(accountInfo);
}catch(Exception e){
logger.error(e);
logger.error(e.getMessage());
return 0;
}
}
令我惊讶的是,尽管我可以看到服务器上闪烁的异常,但我无法在我的 try catch 块中捕获异常:
Mar 13, 2015 9:19:58 AM org.apache.geronimo.transaction.manager.TransactionImpl beforeCompletion
WARNING: Unexpected exception from beforeCompletion; transaction will roll back
javax.persistence.PersistenceException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: ORA-00001: unique constraint (SEC.PORTFOLIO_EXTERNAL_ACCOUNT_U1) violated
【问题讨论】:
-
我认为异常仍然被捕获,尽管事务被回滚。你确定不是这样吗?
-
是的 :( 我在 catch 里面放了一个断点,我无法命中它
标签: java jta apache-tomee