OpenJPA - Nested OneToMany relationships merge issue

天涯浪子 提交于 2019-12-02 07:48:10

There are various bug reports around FK violations in OpenJPA when cascading remove operations to child entities:

The OpenJPA FAQ notes that the following:

http://openjpa.apache.org/faq.html#reorder

Can OpenJPA reorder SQL statements to satisfy database foreign key constraints?

Yes. OpenJPA can reorder and/or batch the SQL statements using different configurable strategies. The default strategy is capable of reordering the SQL statements to satisfy foreign key constraints. However ,you must tell OpenJPA to read the existing foreign key information from the database schema:

It would seem you can force the correct ordering of the statements by either setting the following property in your OpenJPA config

<property name="openjpa.jdbc.SchemaFactory"> value="native(ForeignKeys=true)"/>

or by adding the org.apache.openjpa.persistence.jdbc.ForeignKey annotation to the mapping:

@OneToMany(mappedBy = "classRoom", orphanRemoval = true, cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@org.apache.openjpa.persistence.jdbc.ForeignKey
protected Collection<Desk> desks;

See also:

https://issues.apache.org/jira/browse/OPENJPA-1936

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!