Jav*_*ons 1 java hibernate exception
如何constraintName
使用java从异常中提取,
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);
}
}
Run Code Online (Sandbox Code Playgroud)
上面是我的java代码捕获异常并且它执行了所需的异常,但是我得到了带有约束名称的约束违反异常,
我的问题是如何从抛出的异常中获取约束Name.
我试过这种方式,但它没有用 e.getMessage().split("**")[1]).toString()
谢谢
试试这个:
try {
} catch(HibernateException e) {
if(e instanceof ConstraintViolationException) {
ConstraintViolationException ce = (ConstraintViolationException) e;
String constraintName = ce.getConstraintName();
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
94 次 |
最近记录: |