0
我們開發了無狀態Web服務實現。我們使用JPA作爲ORM層來完成數據庫操作。在服務方法中,我們使用實體管理器來堅持實體。我們無法處理這些異常「由於:java.sql.SQLIntegrityConstraintViolationException:ORA-00001:唯一約束(TIGOSUSCRIPTIONES.SYS_C0020549)違反了Service方法中的異常。 它直接在客戶端結果中拋出以下異常。JPA中未處理的異常
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)
How can I handle this exception? Following is the code we used in service method business logic.
@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;
}
}
你能幫我解決這個問題嗎?