Details
-
Bug
-
Status: Open
-
Major
-
Resolution: Unresolved
-
3.1B1
-
None
-
None
Description
This often happens when vertical inheritance is in use:
T1: ID (PK)
T2: ID (dependent PK), T3_ID, T2_COL
T3: ID (PK)
abstract class O1 // maps to T1
class O2 extends O1 // maps to T1
O3 o3; // maps to 't2.t3'
Object t2Col; maps to T2_COL
class O3 // maps to T3
Saving O2 together with related O3 results in 2 InsertNatchQuery instances generated for T2. One originating from DataDomainFlattenedBucket and containing propagated PK and FK, another - from DataDomainInsertBucket and containing T2_COL changes.
Depending on their (random from what I can tell), a different error would occur. Either a NULL for PK/FK, or duplicate PK. E.g. see the attached example (a reworked version of CAY-1744 with the hack to disable read-only rels). It generates the following inserts and the following error:
INFO: INSERT INTO "session" ("id", "type") VALUES (?, ?)
Oct 9, 2012 9:26:02 PM org.apache.cayenne.log.CommonsJdbcEventLogger logQueryParameters
INFO: [batch bind: 1->id:200, 2->type:'c']
Oct 9, 2012 9:26:02 PM org.apache.cayenne.log.CommonsJdbcEventLogger logUpdateCount
INFO: === updated 1 row.
Oct 9, 2012 9:26:02 PM org.apache.cayenne.log.CommonsJdbcEventLogger logQuery
INFO: INSERT INTO "device" ("id") VALUES
Oct 9, 2012 9:26:02 PM org.apache.cayenne.log.CommonsJdbcEventLogger logQueryParameters
INFO: [batch bind: 1->id:200]
Oct 9, 2012 9:26:02 PM org.apache.cayenne.log.CommonsJdbcEventLogger logUpdateCount
INFO: === updated 1 row.
Oct 9, 2012 9:26:02 PM org.apache.cayenne.log.CommonsJdbcEventLogger logQuery
INFO: INSERT INTO "client_session" ("device_id", "id", "ip") VALUES (?, ?, ?)
Oct 9, 2012 9:26:02 PM org.apache.cayenne.log.CommonsJdbcEventLogger logQueryParameters
INFO: [batch bind: 1->device_id:NULL, 2->id:200, 3->ip:NULL]
Oct 9, 2012 9:26:02 PM org.apache.cayenne.log.CommonsJdbcEventLogger logUpdateCount
INFO: === updated 1 row.
Oct 9, 2012 9:26:02 PM org.apache.cayenne.log.CommonsJdbcEventLogger logQuery
INFO: INSERT INTO "client_session" ("device_id", "id", "ip") VALUES (?, ?, ?)
Oct 9, 2012 9:26:02 PM org.apache.cayenne.log.CommonsJdbcEventLogger logQueryParameters
INFO: [batch bind: 1->device_id:200, 2->id:200, 3->ip:NULL]
Oct 9, 2012 9:26:02 PM org.apache.cayenne.log.CommonsJdbcEventLogger logQueryError
INFO: *** error.
java.sql.SQLIntegrityConstraintViolationException: The statement was aborted because it would have caused a duplicate key value in a unique or primary key constraint or unique index identified by 'SQL121009212602580' defined on 'client_session'.
at org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown Source)
Attachments
Attachments
Issue Links
- is blocked by
-
CAY-1747 New algorithm for tracking changes to DbEntities underlying flattened attributes and relationships
- Open