简体   繁体   English

Hibernate:同表和不同表中的自参考FK

[英]Hibernate : self reference FK in same table as well as different table

I have 2 tables as below我有 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)

Now I want to newly insert records using hibernate现在我想使用 hibernate 新插入记录

session.save(entityObj)

but it gives me但它给了我

exception org.hibernate.StaleStateException

Any help would be appriciate..任何帮助将是appriciate..

COPIED DIRECTLY FROM HIBERNATE JAVADOC, please, google your exception and do some research first.直接从 HIBERNATE JAVADOC 复制,请用谷歌搜索您的异常并先进行一些研究。

Thrown when a version number or timestamp check failed, indicating that the Session contained stale data (when using long transactions with versioning).当版本号或时间戳检查失败时抛出,表明 Session 包含陈旧数据(使用带版本控制的长事务时)。 Also occurs if we try delete or update a row that does not exist.如果我们尝试删除或更新不存在的行,也会发生这种情况。

Note that this exception often indicates that the user failed to specify the correct unsaved-value strategy for a class!请注意,此异常通常表明用户未能为类指定正确的未保存值策略!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM