I have a problem trying to build a generic method that is called from the managed bean and report the errors in the view (end user).
this a managedBean code:
public void processEntity() {
try {
//code save, update, delete or any process here!!!
} catch (Exception e) {
errornotifier.notification("message for user", e);
}
}
this is my errornotifier code:
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);
}
}
The previous code works correctly on glassfish - payara servers but does not work in weblogic since the error returned on this server refers to the instance of the TransactionRolledbackLocalException of the EJBException and I can not cast the same as I did for the PersistenceException to SQLException.
I work the persistence of data with jpa - hibernate, I have only been programming for a few months in java so I hope you forgive me if I do it wrong, if there is a better way to do it please tell me.