【发布时间】:2018-07-10 14:54:09
【问题描述】:
我们开发了无状态 Web 服务实现。我们使用 JPA 作为 ORM 层来执行数据库操作。在服务方法中,我们使用实体管理器来持久化实体。在将相同的记录保存到表中时,我们无法处理这些异常"Caused by: java.sql.SQLIntegrityConstraintViolationException: ORA-00001: unique constraint (TIGOSUSCRIPTIONES.SYS_C0020549) violated" exception in Service method. It is directly throwing the following exception in client result.
Exception in thread "main" javax.xml.ws.soap.SOAPFaultException: Transaction rolled back
at com.sun.xml.internal.ws.fault.SOAP11Fault.getProtocolException(SOAP11Fault.java:178)
at com.sun.xml.internal.ws.fault.SOAPFaultBuilder.createException(SOAPFaultBuilder.java:111)
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:108)
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:78)
at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(SEIStub.java:107)
at $Proxy30.registerSaleOutcome(Unknown Source)
如何处理这个异常。以下是我们在服务方法业务逻辑中使用的代码。
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void recycleOperation(Recycle recycle) throws RecycleFault_Exception{
try{
em.persist(recycle);
} catch(Exception e){
//not coming to this block
log.error("Exception in Data Insertion:"+e.getMessage());
RecycleFault fault = new RecycleFault();
fault.setErrorCode("101");
fault.setMessage("Record is already Existed");
RecycleFault_Exception faultExp = new RecycleFault_Exception("RecycleFault Exception", fault);
throw faultExp;
}
}
你能帮我解决这个问题吗?
提前致谢。
【问题讨论】:
标签: java sql web-services exception-handling