[ 
https://issues.apache.org/jira/browse/CAY-2242?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Matt Watson updated CAY-2242:
-----------------------------
    Attachment: CAY_2242_breaking_test2.patch

The issue occurs when more than one record of that type is being inserted. The 
first time through your loop it gets rid of the old query, which means the next 
time through your loop the existingQuery found only has the 1 Row in it, so it 
will not find an existingRow, which means it will insert a snapshot with a null 
objectId (also with bad infor - missing attributes). The third time through, it 
throws the NPE error in findRowForObjectId because row.getObjectId is null.

I will see if the fix I had ready for this bug handles the "insert two records" 
scenario.

[~ntimofeev] Shall we reopen this ticket or create a new one?

> Vertical Inheritance: Cannot Insert Record With Multiple Flattened 
> Relationships
> --------------------------------------------------------------------------------
>
>                 Key: CAY-2242
>                 URL: https://issues.apache.org/jira/browse/CAY-2242
>             Project: Cayenne
>          Issue Type: Bug
>          Components: Core Library
>    Affects Versions: 4.0.M4
>            Reporter: Matt Watson
>            Assignee: Nikita Timofeev
>              Labels: inheritance, multiple, relationship, vertical
>             Fix For: 4.0.M5
>
>         Attachments: CAY_2242_breaking_test2.patch, 
> CAY_2242_breaking_test.patch
>
>
> Copied and directly related to issue CAY-2122
> When using the following DbEntities:
> IV_OTHER (id, name)
> IV_BASE (id, type, name)
> IV_IMPL (id, attr1, attr2, other1_id, other2_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 other1 = context.newObject(IvOther.class);
> other1.setName("other1");
> IvOther other2 = context.newObject(IvOther.class);
> other2.setName("other2");
> IvImpl impl = context.newObject(IvImpl.class);
> impl.setName("Impl 1");
> impl.setAttr1("attr1");
> impl.setAttr2("attr2");
> impl.setOther1(other1);
> impl.setOther2(other2);
> context.commitChanges();
> {code}
> Committing this errors in the database, because its trying to insert into the 
> IV_IMPL table with a NULL value for OTHER2_ID
> The original issue (and test) was referring to an Entity that only had 1 
> flattened relationship. I recently 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 will upload the breaking test shortly.



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

Reply via email to