You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by "Matt Watson (JIRA)" <ji...@apache.org> on 2017/02/22 01:06:44 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=15877172#comment-15877172 ] 

Matt Watson commented on CAY-2122:
----------------------------------

[~andrus] I just discovered a bug directly related to this. My original issue (and test) was referring to an Entity that only had 1 flattened relationship. Yesterday I had to add another relationship to this Entity, and discovered the same bug pops up again. This time its because the new code does not handle merging the flattenedArcKeys if more than one exists per ObjectId.

I know what I need to do to fix it. Should I reopen this issue or create a new one?

> 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
>             Fix For: 4.0.M4
>
>         Attachments: CAY-2122-test.patch, CAY-2122-test-with-fix.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.15#6346)