Hibernate JPA:更新查询(仅更新版本)被触发,即使它根本没有更改 [英] Hibernate JPA: Update query ( only updating version ) is getting fired even if its not changed at all

查看:266
本文介绍了Hibernate JPA:更新查询(仅更新版本)被触发,即使它根本没有更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我们有一个User;一个用户可以有多个孩子.

Suppose, we have a User ; one user can have multiple Childs.

现在,当我插入一个孩子时;我叫user.addChild(),以便更新坐在JVM中的用户对象..尽管实际上用户名的数据库记录没有任何变化,因为它是OneToMany.

Now, when I am inserting a child; I call user.addChild() so that user object sitting in JVM is updated .. though actually nothing changes on database record of User as it is OneToMany.

当我检查SQL时;连同插入孩子;触发了另一个查询:

When I am checking SQL; along with insert into child; an additional query is getting fired :

update User set version=? where id=? and version=?

任何想法为何?以及如何解决这个问题

Any ideas why ? and how to fix this

推荐答案

如果它是双向关系的所有者,则其行为与指定的行为相同.默认情况下,单向一对多使用联接表,然后还应该更新版本.在规范中,这是用以下单词来表示的:

It behaves as specified, if this is owning side of bidirectional relationship. By default unidirectional one-to-many uses join-table, and also then version should be updated. In specification this is told with following words:

所有非关系字段和属性以及所有关系
该实体拥有的所有权包含在版本检查中.
...
这包括在联接表中维护的拥有的关系.

All non-relationship fields and properties and all relationships
owned by the entity are included in version checks.
...
This includes owned relationships maintained in join tables.

这篇关于Hibernate JPA:更新查询(仅更新版本)被触发,即使它根本没有更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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