You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by "Andrus Adamchik (JIRA)" <ji...@apache.org> on 2016/10/05 08:20:20 UTC

[jira] [Commented] (CAY-2122) Vertical Inheritance: Cannot Insert Record For Implementing Class with Attribute And Relationship

    [ https://issues.apache.org/jira/browse/CAY-2122?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15548039#comment-15548039 ] 

Andrus Adamchik commented on CAY-2122:
--------------------------------------

Hi Matt,

thanks for the bug report and the patch. It almost works :) The following line is problematic for many-to-many flattened case:

{noformat} 
         DataNode node = parent.getDomain().lookupDataNode(flattenedEntity.getDataMap());
         Map flattenedSnapshot = flattenedArcKey.buildJoinSnapshotForInsert(node);
-        relationInsertQuery.add(flattenedSnapshot);
+        relationInsertQuery.add(flattenedSnapshot, flattenedArcKey.id1.getSourceId());
{noformat} 

as it messes up source ObjectId , loading join table values in it. We didn't have a direct test for this condition, but PostCommitFilter_All_FlattenedIŠ¢ from cayenne-lifecycle failed as a result. I think we might need to redo DataDomainFlattenedBucket, storing FlattenedArcKey's instead of insert batches inside addFlattenedInsert method. And then generate the queries out of them in appendInserts.. I think this is a good idea in general and should help us to avoid this issue.

> Vertical Inheritance: Cannot Insert Record For Implementing Class with Attribute And Relationship
> -------------------------------------------------------------------------------------------------
>
>                 Key: CAY-2122
>                 URL: https://issues.apache.org/jira/browse/CAY-2122
>             Project: Cayenne
>          Issue Type: Bug
>          Components: Core Library
>    Affects Versions: 4.0.M3
>            Reporter: Matt Watson
>            Assignee: Andrus Adamchik
>              Labels: inheritance, null, relationship, vertical
>         Attachments: CAY-2122-test-with-fix.patch, CAY-2122-test.patch
>
>
> When using the following DbEntities:
> IV_OTHER (id, name)
> IV_BASE (id, type, name)
> IV_IMPL (id, attr1, other_id) (vertically inherits IV_BASE)
> all fields are non-null
> We end up with ObjEntities:
> IvOther
> IvBase (abstract)
> IvImpl extends IvBase
> When running the following code:
> {code:java}
> IvOther other = context.newObject(IvOther.class);
> other.setName("other");
> IvImpl impl = context.newObject(IvImpl.class);
> impl.setName("Impl 1");
> impl.setAttr1("attr1");
> impl.setOther(other);
> context.commitChanges();
> {code}
> Committing this errors in the database, because its trying to insert into the IV_IMPL table with a NULL value for OTHER_ID
> {code}
> [main] INFO org.apache.cayenne.log.CommonsJdbcEventLogger - INSERT INTO IV_OTHER (ID, NAME) VALUES (?, ?)
> [main] INFO org.apache.cayenne.log.CommonsJdbcEventLogger - [bind: 1->ID:200, 2->NAME:'other']
> [main] INFO org.apache.cayenne.log.CommonsJdbcEventLogger - === updated 1 row.
> [main] INFO org.apache.cayenne.log.CommonsJdbcEventLogger - INSERT INTO IV_BASE (ID, NAME, TYPE) VALUES (?, ?, ?)
> [main] INFO org.apache.cayenne.log.CommonsJdbcEventLogger - [bind: 1->ID:200, 2->NAME:'Impl 1', 3->TYPE:'I']
> [main] INFO org.apache.cayenne.log.CommonsJdbcEventLogger - === updated 1 row.
> [main] INFO org.apache.cayenne.log.CommonsJdbcEventLogger - INSERT INTO IV_IMPL (ATTR1, ID, OTHER_ID) VALUES (?, ?, ?)
> [main] INFO org.apache.cayenne.log.CommonsJdbcEventLogger - [bind: 1->ATTR1:'attr1', 2->ID:200, 3->OTHER_ID:NULL]
> [main] INFO org.apache.cayenne.log.CommonsJdbcEventLogger - *** error.
> java.sql.SQLException: Attempt to insert null into a non-nullable column: column: OTHER_ID table: IV_IMPL in statement [INSERT INTO IV_IMPL (ATTR1, ID, OTHER_ID) VALUES (?, ?, ?)]
> {code}
> If there was only an attribute in IV_IMPL, or only a relationship on IV_IMPL it would work fine. But the DataDomainFlushAction is using separate InsertBatchQuery to handle the attributes and another one to handle the relationships.
> I have not yet figured out how to solve, but will continue to look into it.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)