openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Benjamin S Vera-Tudela <>
Subject OpenJPA Relationships Question
Date Fri, 09 Oct 2009 16:41:16 GMT

Hi ....

I have a servlet that handles incoming HTTP requests and uses information
in the request to create a persistent relationship between 2 classes using
JPA. The database schema has 3 tables: Class1, Class2, and Relationship
(see MyDataAppRDB), where Relationship's primary key consists of the
primary keys of both Class1 and Class2 which are also referenced as foreign
keys. The servlet invokes a method called createRelationship (see
MyDataAppWeb) which starts a transaction through the EntityManager to
create a Class2 object if one isn't found in the database and to create a
relationship between Class1 (assumed to exist already) and Class2.

I am having a problem with the createRelationship method at the time of
committing the transaction where the database (DB2) throws error 23503 (see
below for error details).

I am not sure if the problem is related to 1) the order of my persist calls
within the transaction (see TransactionManager class in MyDataAppRDB); 2)
the contents of my persistence.xml file (see MyDataAppJPA -- I am not yet
very familiar with the values in the persistence.xml  schema); or 3) the
way I implement my JPA classes (see MyDataJPA -- in particular the
Relationship class which contains a composite key that references foreign

Can someone please help me understand what I might be doing wrong? I am
attaching my simplified files below.

DB2 Error 23503:

An UPDATE or INSERT operation attempted to place a value in a foreign key
of the object table; however, this value was not equal to some value of the
parent key of the parent table. When a row is inserted into a dependent
table, the insert value of a foreign key must be equal to the value of the
parent key of some row of the parent table in the associated relationship.
When the value of the foreign key is updated, the update value of a foreign
key must be equal to the value of the parent key of some row of the parent
table of the associated relationship. System action: The UPDATE or INSERT
statement cannot be executed. The object table is unchanged. Programmer
response: Examine the insert or update value of the foreign key first, and
then compare it with each of the parent key values of the parent table to
determine the cause of the problem.

(See attached file:

Benjamin S. Vera-Tudela
SWG Middleware Strategy
Ph: (512)-286-9073 T/L 363-9073
View raw message