관리 빈에서 호출 된 일반 메소드를 빌드하고 뷰의 오류 (엔드 유저)를보고하는 중 문제점이 있습니다. SQLException에 대한 EJBException 캐스팅
이것을 ManagedBean은 코드 :public static void notification(String msj, Exception exep) {
String sqlMsj = null;
try {
if (exep instanceof EJBException) {
EJBException ejbException = (EJBException) exep;
if (ejbException.getCausedByException().getCause() instanceof PersistenceException) {
PersistenceException persistExep = (PersistenceException) ejbException.getCausedByException().getCause();
Throwable throwable = persistExep;
if (throwable instanceof SQLException) {
SQLException sqlex = (SQLException) throwable;
sqlMsj = ""; //-->validatios and set message agree sqlcode ...
}
}
}
} catch (Exception ex) {
msj = msj + ex.getMessage();
}finally {
FacesContext.getCurrentInstance().addMessage(null,new FacesMessage(FacesMessage.SEVERITY_INFO, "Executed", msj));
logger.error("notification failed", msj);
}
}
앞의 코드는 글래스 피쉬에서 제대로 작동 - payara 서버 있지만 오류가 반환 이후 웹 로직에서 작동하지 않습니다 :이 내 errornotifier 코드가
public void processEntity() {
try {
//code save, update, delete or any process here!!!
} catch (Exception e) {
errornotifier.notification("message for user", e);
}
}
입니다 이 서버는 EJBException의 TransactionRolledbackLocalException 인스턴스를 참조하며 PersistenceException에 대해 SQLException을 수행 한 것과 똑같이 캐스트 할 수 없습니다.
저는 jpa로 데이터의 지속성을 작동합니다 - 최대 절전 모드로, 몇 달 동안 자바로 프로그래밍 했으므로 잘못 할 경우 용서 해주시기 바랍니다. 더 좋은 방법이 있다면 알려주세요. .
달성하려는 목표는 무엇입니까? 'try' 블록에있는 코드는 아무런 영향을 미치지 않습니다 – ytg
try 블록에서 데이터베이스의 지속성 (insert, update, delete 등)이나 java 문이 필요한 것에 따라 실행할 수 있습니다. 코드가 올바르게 작동합니다. 서버 glassfish 및 payara 있지만 weblogic 않습니다. – fjrincon0
글래스 피시에서 실제로 작동하는 진술에 따라 귀하의 질문에 대한 답변이 다를 수 있습니다. – ytg