如何从Hibernate ConstraintViolationException中提取实际的实体和属性名称 [英] How to extract actual entity and property name that is a duplicate from Hibernate ConstraintViolationException

查看:177
本文介绍了如何从Hibernate ConstraintViolationException中提取实际的实体和属性名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够以rdbms中性方式从ConstraintViolationException消息中提取实体和属性......可以这样做吗?如果是这样的话怎么样?

解决方案

查看hibernate源代码:org.hibernate.exception.SQLStateConverter将SQLException.SQLState转换为适当的休眠异常。 SQLState是唯一与供应商无关的标准化数据,您必须找出错误原因。 Java API文档可以遵循两种错误代码和消息标准之一......但是没有指定错误细节的标准。

所以我认为不,它可以不要做,除非你手头有所有rdbms来亲自测试和解释错误消息字符串。


I would like to be able to extract the entity and property from the ConstraintViolationException message in a rdbms neutral way... Can this be done ? if so how ?

解决方案

Look into the hibernate source code: org.hibernate.exception.SQLStateConverter translates the SQLException.SQLState into the appropriate hibernate exception. SQLState is the only vendor-independent normalized data you have to find out the error cause. Java API documents it can follow one of two standards for error codes and messages... but there is no standard for specifying error detail.

So I think no, it can't be done, unless you have all rdbms at hand to test and interpret the error message strings yourself.

这篇关于如何从Hibernate ConstraintViolationException中提取实际的实体和属性名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆