JPA单向@OneToMany性能 [英] JPA unidirectional @OneToMany performance
问题描述
我有两个实体单向@OneToMany Lazy
关系。当我尝试添加一个孩子时,看起来像Hibernate 4(我的JPA提供者)实际执行
- 选择查询
- 在连接表上删除所有具有该父母标识的孩子
- 重新插入连接表上的所有孩子和新孩子
如何让Hibernate在不改变我的关系的情况下插入我希望的子项?
默认情况下,单向 @OneToMany
关系将使用连接表,它将按照我的问题执行操作。如果您使用的是JPA2并且不对父节点使用多态,则可以添加 @JoinColumn
,这将在children表上创建外键而不是另一个连接表。 JPA提供程序然后将不执行删除并重新插入。
I have two entities with unidirectional @OneToMany Lazy
relationship. When I try to add a child, it seems like Hibernate 4 (my JPA provider) actually performs
- Select query
- Delete all children with that parent id on join table
- Reinsert back all and the new child on join table
How to make Hibernate to just insert the child I wish, without changing my relationship?
By default, a unidirectional @OneToMany
relationship will use a join table, it will perform operation as my question. If you are using JPA2 and do not use polymorphic on parent, you may add @JoinColumn
, which will create foreign key on children table instead of another join table. JPA provider then will not perform delete and reinsert again.
这篇关于JPA单向@OneToMany性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!