Hibernate:同一个表中的自引用FK以及不同的表

时间:2011-06-29 08:05:42

标签: java hibernate

我有2张表格如下

historyQuestions
=====================
question_id bigint(2) PK
question_master_id bigint(2) fk references question_master(question_id)
parent_question_id bigint(2) fk references historyQuestions(question_id)
parent_answer_id bigint(2) fk references historyAnswers(answer_id)

historyAnswers
=====================
answer_id bigint(2) pk
question_id bigint(2) fk references historyQuestions(question_id)
answer_master_id bigint(2) fk references answer_master(answer_id)

现在我想使用hibernate

重新插入记录
session.save(entityObj)

但它给了我

exception org.hibernate.StaleStateException

任何帮助都是适当的..

1 个答案:

答案 0 :(得分:0)

直接来自HIBERNATE JAVADOC,请先查看您的例外并先做一些研究。

当版本号或时间戳检查失败时抛出,指示Session包含过时数据(当使用具有版本控制的长事务时)。如果我们尝试删除或更新不存在的行,也会发生这种情况。

请注意,此异常通常表示用户未能为类指定正确的unsaved-value策略!