困扰好几天了,Hibernate插入时报ConstraintViolationException异常

qqliang1314 2012-05-14 07:02:26
运行时控制台输出:
Hibernate: select user0_.password_md5 as col_0_0_ from t_user user0_ where user0_.user=?
Hibernate: insert into t_user (user, password_md5, name, email, phone, qq) values (?, ?, ?, ?, ?, ?)

浏览器提示的错误信息为:
{"result":"could not insert: [zhao.bbs.model.User]; nested exception is org.hibernate.exception.ConstraintViolationException: could not insert: [zhao.bbs.model.User]"}

user.hbm.xml配置文件:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping >
<!-- 映射 user 表 -->
<class name="zhao.bbs.model.User" table="t_user" >
<id name="id" column="id" >
<generator class="identity"/>
</id>
<property name="user" column="user" />
<property name="password_MD5" column="password_md5"/>
<property name="name" />
<property name="email" />
<property name="phone" />
<property name="qq" />
</class>

</hibernate-mapping>
topics.hbm.xml配置文件:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping >

<class name="zhao.bbs.model.Topic" table="t_topics" >
<id name="id" >
<generator class="identity"/>
</id>
<property name="topic" />
<property name="postTopicTime" column="post_topic_time" />
<property name="viewCount" column="view_count" />
<property name="replyCount" column="reply_count" />
<property name="lastReplyTime" column="last_reply_time" />
<property name="topicPath" column="topic_path" />
<!--将 Topic 和 user 属性映射成为多对一关系 -->
<many-to-one name="user" column="user_id"
class="zhao.bbs.model.User" cascade="all" lazy="false">
</many-to-one>
<!--将 Topic 和lastReplyUser 属性映射成为多对一关系 -->
<many-to-one name="lastReplyUser" column="last_reply_user_id"
class="zhao.bbs.model.User" cascade="all" lazy="false">
</many-to-one>
</class>

</hibernate-mapping>

reviews.hbm.xml配置文件:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping >
<!-- 映射review 表 -->
<class name="zhao.bbs.model.Review" table="t_reviews" >
<id name="id" >
<generator class="identity"/>
</id>
<property name="topicId" column="topic_id" />
<property name="reviewTime" column="reiview_time"/>
<!--将 Review 和reviewUser 属性映射成为多对一关系 -->
<many-to-one name="reviewUser" column="review_user_id"
class="zhao.bbs.model.User" cascade="all" lazy="false">
</many-to-one>
</class>

</hibernate-mapping>

MySql数据库中表t_topics的两个外键均为 t_user表的id;表t_reviews的外键也是 t_user表的id
到底是哪出问题了呢
...全文
2120 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
回南山种豆 2012-05-15
  • 打赏
  • 举报
回复
看哈这篇https://forum.hibernate.org/viewtopic.php?f=1&t=1005913
回南山种豆 2012-05-15
  • 打赏
  • 举报
回复
意思是说你的约束 有问题。
qqliang1314 2012-05-14
  • 打赏
  • 举报
回复
能说的详细一点吗,是由什么造成的,谢谢了
_jerrytiger 2012-05-14
  • 打赏
  • 举报
回复
约束冲突异常

56,679

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧