APAR status
Closed as suggestion for future release.
Error description
Make reference to below: OpenJPA JIRA: https://issues.apache.org/jira/browse/OPENJPA-1936
Local fix
Will be fix for next release once JPA Dev concludes the review per Spec. Serving as place holder.
Problem summary
Problem conclusion
Temporary fix
Comments
Take the following exception: org.apache.openjpa.persistence.EntityExistsException: ORA-02292: integrity constraint (SYSTEM.SYS_C004678) violated - child record found {prepstmnt 31447311 DELETE FROM Child WHERE id = ? [params=(int) 0]} [code=2292, state=23000] FailedObject: hat.entities.Child-0 This exception can occur when OpenJPA does not know about a database 'Foreign Key' constraint. To explain this issue and possible solutions, lets look at an example. Take the following SQL to create two tables in a database: CREATE TABLE PARENT ( "ID" INT NOT NULL, PRIMARY KEY ("ID") ) CREATE TABLE CHILD ( "ID" INT NOT NULL, "PARENT_ID" INT, PRIMARY KEY ("ID"), FOREIGN KEY ("PARENT_ID") REFERENCES "PARENT" ("ID") ) Take the following two entities: public class Parent implements Serializable { @Id private int id; @OneToMany(mappedBy = "parent", cascade = CascadeType.ALL, fetch = FetchType.EAGER, orphanRemoval = true) private Collection<Child> childs; ......... public class Child implements Serializable { @Id private int id; @ManyToOne private Parent parent; ......... If a scenario is executed in which an existing Parent is removed, an existing Child(s) associated with the Parent will also be removed given the definition of the @OneToMany relationship. However, when OpenJPA executes the SQL to remove the Parent and Child, the SQL to remove the Parent will be executed first. Given the 'FOREIGN KEY' constraint on the Child table, a database will throw some kind of 'constraint violation' exception when a Parent is removed before its Child (if it were not for the 'FOREIGN KEY' constraint on the Child table, the SQL order would be fine). In this case, OpenJPA should execute the SQL to remove the Child first, then the Parent. However, by default, OpenJPA knows nothing about the 'FOREIGN KEY' constraint defined on the Child table and OpenJPA never assumes that there are database constraints for relationships. As a result, OpenJPA does not take them into account when executing SQL. To tell OpenJPA that there are database level constraints, and thus to effect the order of the SQL in this case, a user can perform one of the following options: 1) Use the @ForeignKey annotation (org.apache.openjpa.persistence.jdbc.ForeignKey) in entities (on the ToOne fields). 2) Have OpenJPA read in the table definitions from the database by adding the following property: <property name="openjpa.jdbc.SchemaFactory" value="native(ForeignKeys=true)"/> This property can be added to a persistence.xml file. It can also be set globally as a JVM system property or global to an application. For the latter, OpenJPA offers an optional resource file named openjpa.xml to set configuration properties, as described here: http://openjpa.apache.org/builds/latest /docs/manual/manual.html#ref_guide_conf _specify. An example of the contents of the openjpa.xml file is as follows: <?xml version="1.0" encoding="UTF-8"?> <persistence xmlns="http://java.sun.com/xml/ns/persi stence" xmlns:xsi="http://www.w3.org/2001/XMLSc hema-instance" version="1.0" xsi:schemaLocation="http://java.sun.com /xml/ns/persistence http://java.sun.com/xml/ns/persistence/ persistence_1_0.xsd"> <persistence-unit name=""> <properties> <property name="openjpa.jdbc.SchemaFactory" value="native(ForeignKeys=true)"/> </properties> </persistence-unit> </persistence> Notice that the persistence-unit name is blank. This is expected, the name isn't actually used. As the OpenJPA document listed above points out, this file needs to be on the CLASSPATH. As an example (but not limited to), a user can place this file in the same location as the persistence.xml file. Or, a user can place the file in a .jar file and place the .jar file in the lib directory of an ear. While either of these two options will properly handle the above scenario, it can be argued that OpenJPA should detect the 'FOREIGN KEY' constraint, and not require a user to add an annotation to their code or set a property. An OpenJPA JIRA (http://issues.apache.org/jira/browse/OPENJPA-1936) will be used to investigate possible solutions to change the way the constraints are detected. When this JIRA is complete, it will be shipped in a future version of WebSphere Application Server.
APAR Information
APAR number
PM33268
Reported component name
WEBS APP SERV N
Reported component ID
5724H8800
Reported release
700
Status
CLOSED SUG
PE
NoPE
HIPER
NoHIPER
Special Attention
NoSpecatt
Submitted date
2011-02-21
Closed date
2011-05-20
Last modified date
2011-05-20
APAR is sysrouted FROM one or more of the following:
APAR is sysrouted TO one or more of the following:
Fix information
Applicable component levels
[{"Business Unit":{"code":"BU059","label":"IBM Software w\/o TPS"},"Product":{"code":"SSEQTP","label":"WebSphere Application Server"},"Component":"","ARM Category":[],"Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"7.0","Edition":"","Line of Business":{"code":"LOB45","label":"Automation"}}]
Document Information
Modified date:
10 February 2022