You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openjpa.apache.org by "chenlin (Jira)" <ji...@apache.org> on 2020/07/31 09:22:00 UTC

[jira] [Commented] (OPENJPA-2708) Integrity constraint violated while cascade merging entity with @ManyToOne relationship

    [ https://issues.apache.org/jira/browse/OPENJPA-2708?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17168561#comment-17168561 ] 

chenlin commented on OPENJPA-2708:
----------------------------------

TestRun.java 
In this example, merge the parent entity instead of the child entity. 
so, "entityManager.merge(template) --> entityManager.merge(type)"; 

> Integrity constraint violated while cascade merging entity with @ManyToOne relationship
> ---------------------------------------------------------------------------------------
>
>                 Key: OPENJPA-2708
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-2708
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: jpa, kernel
>    Affects Versions: 2.4.0, 2.4.1, 2.4.2
>         Environment: OS: CentOS/RHEL, Archlinux, Ubuntu
> RDBMS: Oracle Database 12c Standard Edition Release 12.1.0.2.0
> Environments: JavaSE and JavaEE (TomEE 1.7.4)
> JDBC driver version: ojdbc6, ojdbc7(12.1.0.2), ojdbc8
>            Reporter: Riccardo Ambrosio
>            Priority: Major
>              Labels: cascade, manytoone, merge, oracle
>         Attachments: failcase.zip
>
>
> When trying to merge an Entity which has a ManyToOne relationship annotated as follows:
> @ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH, CascadeType.DETACH}, fetch = FetchType.EAGER)
> I get an ORA-02291: integrity constraint violated - parent key not found. It looks like OpenJPA is trying to insert the parent entity before inserting the children. This only happens to me when using an Oracle Database and when the children are new entities (the update works fine). I've reproduced the issue in a simple testcase (see attachment) using open-jpa-all jar in a JavaSE environment, but I've also tested it using TomEE in a JavaEE environment.
> I'm still a little skeptical that such an issue could have gone unnoticed for such a long time, so I'm pretty sure I am doing something wrong here. If that's the case please forgive me for opening this issue, but I'm out of ideas and this is causing me some serious head ache.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)