Java 如何从Hibernate异常中提取constraintName

Java 如何从Hibernate异常中提取constraintName,java,hibernate,exception,Java,Hibernate,Exception,如何使用java从异常中提取constraintName catch(HibernateException e) { if (ExceptionChecker.isUniqueConstraintViolated(e)) { if (log.isDebugEnabled()) { log.debug("save HibernateException" + e

如何使用java从异常中提取
constraintName

catch(HibernateException e)
        {
            if (ExceptionChecker.isUniqueConstraintViolated(e)) 
            {
                if (log.isDebugEnabled()) {

                    log.debug("save HibernateException" + e.getMessage());

                }

            }
            else
            {   
                throw ExceptionHandler.handleHibernateException(this.getClass().toString(), log, e);
            }
        }
上面是我的java代码,它捕获了异常,并执行了所需的异常,但我得到了约束名为的约束冲突异常

我的问题是如何从抛出的异常中获取约束名称

我尝试了这种方法,但没有成功
e.getMessage().split(“**”[1]).toString()

谢谢

试试这个:

try {

} catch(HibernateException e) {
  if(e instanceof ConstraintViolationException) {
    ConstraintViolationException ce = (ConstraintViolationException) e;
    String constraintName = ce.getConstraintName();
  }
}
试试这个:

try {

} catch(HibernateException e) {
  if(e instanceof ConstraintViolationException) {
    ConstraintViolationException ce = (ConstraintViolationException) e;
    String constraintName = ce.getConstraintName();
  }
}

谢谢@Miljenko成功了,我无法接受答案,我将接受答案和+1:)谢谢@Miljenko成功了,我无法接受答案,我将接受答案和+1:)