0 Replies Latest reply: Jan 20, 2014 12:13 PM by user8797519 RSS

    Zero value key to a referenced table

    user8797519

      I have inherited an application and I have upgraded to Oracle Toplink 11g.(not EclipseLink).

      I'm getting a problem with updating rows which contain references to other tables which have a zero value for a remote primary key of type int.

       

      I have now created a simplified version of this starting from scratch with just two tables and two classes. (Party and Address)

      Both tables have primary keys of type int.

       

      I use the project workbench to map the DB to the classes.

      The mappings are simple (direct value mappings for the most part).

      With one one-to-many reference. (A Party has an Address, but the same Address can be referenced by many Party).

      From the workbench I export the Java source.

       

      I have written some simple tests.

      I can create records with values of primary key equal or greater than zero for both tables.

      I can associate many rows to one row in the one-to-many mapping.

       

      But, one thing doesn't work.

       

      I'm trying in this case to create a Party record, referencing an existing Address.

      If I have a reference from the Party table to the Address table with an address id equal to zero I get an exception on the UnitOfWork.commit, like this:

      Exception [TOPLINK-4002] (Oracle TopLink - 11g Release 1 (11.1.1.6.0) (Build 111018)): oracle.toplink.exceptions.DatabaseException

      Internal Exception: java.sql.SQLException: ORA-00001: unique constraint (PARTIES.ADR_PK) violated

      Error Code: 1

      Call: INSERT INTO PTY_ADDRESS (ADR_ID, ADR_STREET, ADR_COUNTRY, ADR_NAME, ADR_CITY) VALUES (?, ?, ?, ?, ?)

        bind => [0, street, country, venue, city]

       

      Any other value than zero works fine.

       

      I can supply more detail if it will help, but let me leave it simple for the moment.

      Perhaps this is a known problem?

       

      Any ideas?

       

      John D.