开发者

Seam / Hibernate - getting ORA message text

    try {
        if (schId != null) {
            log.info(">>&开发者_开发问答gt; save");
            schedule = em.merge(schedule);

            em.persist(schedule);
        } else {
            em.persist(schedule);
        }

        em.flush();
        ret = "ok";
    } catch (Exception err) {
        ret = err.getMessage();
        err.printStackTrace();

        facesMessages.addFromResourceBundle(Severity.ERROR, "databaseError", ret);
    }

When I have duplicate key error err.getMessage() returns org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch

In the stacktrace there is this error too: java.sql.BatchUpdateException: ORA-00001: unique constraint (ACM.SCH_UK) violated

How can I get this ORA-00001 message as a string, instead of the org.hibernate.exception.ConstraintViolationException text?


java.sql.BatchUpdateException is the root cause of your PersistenceException, you can extract it as follows:

public static Throwable getRootCause(Throwable ex) {
    while (true) {
        Throwable cause = ex.getCause();
        if (cause == null) return ex;
        ex = cause;
    }
}

.

ret = getRootCause(ex).getMessage();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜