Это одна часть моего кода. Я использую транзакцию JTA, и этот кусок кода бросает уникальное исключение ограничений.Как сделать обработку исключений в управляемой контейнером транзакции 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;
}
}
К моему удивлению я не могу поймать исключение в моем поймать блок Ьги, хотя я могу видеть исключение мигающего на сервере:
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
Я думаю, что исключение все еще поймано, несмотря на отмену транзакции. Вы уверены, что это не так? – Magnilex
Да :(Я поставил точку останова внутри catch, и я не могу ударить его – JackSparrow