WLS JPA 10.3: Joined Inheritance Strategy (Kodo) Is Not Working With Foreign Key Constraints On Child Tables (Doc ID 1128775.1)

Last updated on MARCH 09, 2012

Applies to:

Oracle Weblogic Server - Version: 10.3 to 10.3.1
Information in this document applies to any platform.

Symptoms

Joined Inheritance Strategy (for Kodo) is not working with foreign key constraints on child tables, when inserting and deleting values from database.

To illustrate the above statement look at the below example:
Let's say we have two Database tables as below:
1. Person
2. Employee


CREATE TABLE "VG"."TST_PERSON"
("ID" NUMBER NOT NULL ENABLE,
"TYPE" VARCHAR2(20) NOT NULL ENABLE,
"NAME" VARCHAR2(100) NOT NULL ENABLE,
CONSTRAINT "TST_PERSON_PK" PRIMARY KEY ("ID"));
/

CREATE TABLE "VG"."TST_EMPLOYEE"
("ID" NUMBER NOT NULL ENABLE,
"EMPLOYEE_ID" NUMBER NOT NULL ENABLE,
CONSTRAINT "TST_EMPLOYEE_PK" PRIMARY KEY ("ID"),
CONSTRAINT "TST_EMPLOYEE_UK1" UNIQUE ("EMPLOYEE_ID"),
CONSTRAINT "TST_EMPLOYEE_TST_PERSON_FK1" FOREIGN KEY ("ID")
REFERENCES "VG"."TST_PERSON" ("ID") ON DELETE CASCADE ENABLE
);


Person Class
============
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@DiscriminatorColumn(name = "TYPE", discriminatorType = DiscriminatorType.STRING, length = 20)
@Table(name = "TST_PERSON")
public abstract class Person implements Serializable {
@Id
@Column(name = "ID")
private long id;

@Column(name = "name")
private String name;

public Person() {
}

public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
Employee Class which extends Person
===================================
@Entity
@Table(name = "TST_EMPLOYEE")
@PrimaryKeyJoinColumn(name="ID", referencedColumnName="ID")
@DiscriminatorValue("EMPLOYEE")
public class Employee extends Person {

private static final long serialVersionUID = 4866746462661669607L;

@Column(name = "EMPLOYEE_ID")
private long employeeId;

public Employee() {
}

public long getEmployeeId() {
return employeeId;
}

public void setEmployeeId(long employeeId) {
this.employeeId = employeeId;
}
}


When trying to insert or delete employee with below sample code:
for (int i = 0; i <100; i++) {
Employee employee = new Employee();
System.out.print(i + ".. ");
employee.setId(i);
employee.setName("Sunil");
employee.setEmployeeId(10+i);
statelessSession.create(employee);
statelessSession.delete(i);
}

You will see the below exception intermitantly:
<openjpa-1.1.0-r422266:657916 nonfatal store error> org.apache.openjpa.util.ReferentialIntegrityException: ORA-02291: integrity constraint (NSP.ACCESS_POINT_ON_DEMAND_FK) violated - parent key not found
{prepstmnt 9176 INSERT INTO CAR_ACCESS_POINTS (ID, APN) VALUES (?, ?) [params=(long) 6044, (String) sdfsdfdsf]} [code=2291, state=23000]
FailedObject: com.tekelec.cssg.nsp.customercare.ejb.jpa.APN@2d23c54
at org.apache.openjpa.jdbc.sql.SQLExceptions.narrow(SQLExceptions.java:144)
at org.apache.openjpa.jdbc.sql.DBDictionary.newStoreException(DBDictionary.java:4150)
at org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java:102)
at org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java:72)
at kodo.jdbc.kernel.BatchingPreparedStatementManager.flushInternal(BatchingPreparedStatementManager.java:214)
Caused by: <openjpa-1.1.0-r422266:657916 nonfatal store error>
org.apache.openjpa.util.OptimisticException: An optimistic lock violation
was detected when flushing object instance
"com.tekelec.gps.ias.nsp.sample.ejb3.entity.Employee-com.tekelec.gps.ias.nsp.
sample.ejb3.entity.Employee-0" to the data store. This indicates that the object was concurrently modified in another transaction.FailedObject:
com.tekelec.gps.ias.nsp.sample.ejb3.entity.Employee-com.tekelec.gps.ias.nsp.sample.ejb3.entity.Employee-0
at kodo.jdbc.kernel.BatchingPreparedStatementManager.checkUpdate(BatchingPreparedStatementManager.java:354)
at kodo.jdbc.kernel.BatchingPreparedStatementManager.flushInternal(BatchingPreparedStatementManager.java:208)
at kodo.jdbc.kernel.BatchingPreparedStatementManager.flush(BatchingPreparedStatementManager.java:188)
at kodo.jdbc.kernel.ConstraintUpdateManager.flush(ConstraintUpdateManager.java:90)
at org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.flush(AbstractUpdateManager.java:89)
at org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.flush(AbstractUpdateManager.java:72)
at org.apache.openjpa.jdbc.kernel.JDBCStoreManager.flush(JDBCStoreManager.java:549)
at org.apache.openjpa.kernel.DelegatingStoreManager.flush(DelegatingStoreManager.java:130)
at org.apache.openjpa.datacache.DataCacheStoreManager.flush(DataCacheStoreManager.java:554)
at org.apache.openjpa.kernel.DelegatingStoreManager.flush(DelegatingStoreManager.java:130)

Changes

None.

Cause

Sign In with your My Oracle Support account

Don't have a My Oracle Support account? Click to get started

My Oracle Support provides customers with access to over a
Million Knowledge Articles and hundreds of Community platforms