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 2011/04/01 11:25:05 UTC

[jira] [Commented] (CAY-1444) NPE when persisting a newly instatiated object

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

Andrus Adamchik commented on CAY-1444:
--------------------------------------

Hi Dzmitry. Diagnostics of the problem seems about right. Although I guess we need to fix it upstream somewhere. Doing this check at the BatchQuery level seems a bit out of place (??)

> NPE when persisting a newly instatiated object
> ----------------------------------------------
>
>                 Key: CAY-1444
>                 URL: https://issues.apache.org/jira/browse/CAY-1444
>             Project: Cayenne
>          Issue Type: Bug
>          Components: Core Library
>    Affects Versions: 3.0
>            Reporter: Thomas Lopatic
>            Priority: Minor
>         Attachments: cay-1444.patch
>
>
> I get a NPE when persisting a newly created object. My object has an auto-increment primary key and, other than that, contains references to three more objects. Here's what it looks like.
> <obj-entity name="Settings" className="xxx.Settings" lock-type="optimistic" dbEntityName="Settings">
>   <obj-attribute name="name" type="java.lang.String" db-attribute-path="name"/>
> </obj-entity>
> <obj-relationship name="settingsCity" source="Settings" target="City" deleteRule="Nullify" db-relationship-path="settingsCity"/>
> <obj-relationship name="settingsUser" source="Settings" target="User" deleteRule="Nullify" db-relationship-path="settingsUser"/>
> <db-entity name="Settings" schema="xxx">
>   <db-attribute name="id" type="BIGINT" isPrimaryKey="true" isGenerated="true" isMandatory="true"/>
>   <db-attribute name="idCity" type="BIGINT"/>
>   <db-attribute name="idUser" type="BIGINT"/>
>   <db-attribute name="name" type="VARCHAR" length="50"/>
> </db-entity>
> <db-relationship name="settingsCity" source="Settings" target="City" toMany="false">
>   <db-attribute-pair source="idCity" target="id"/>
> </db-relationship>
> <db-relationship name="settingsUser" source="Settings" target="User" toMany="false">
>   <db-attribute-pair source="idUser" target="id"/>
> </db-relationship>
> I instantiate my Settings object and leave the name, settingsCity, and settingsUser object references at null. Then I commit. What then happens is that DataDomainDBDiffBuilder.buildDBDiff() returns null, because dbDiff.isEmpty() is true. This null reference then ends up in InsertBatchQuery.objectSnapshots.
> So, it looks like if all members of a newly created object are null, no differences are detected. Note that I use a database-generated auto-increment primary key. So, the primary key is possibly also still null at this stage.
> The null reference in InsertBatchQuery.objectSnapshots ultimately leads to the following NPE.
> 13:16:16,542  INFO QueryLogger:357 - INSERT INTO xxx.Settings (idCity, idUser, name) VALUES (?, ?, ?)
> 13:16:16,543  INFO QueryLogger:453 - *** error.
> java.lang.NullPointerException
> 	at org.apache.cayenne.query.BatchQuery.getValue(BatchQuery.java:164)
> 	at org.apache.cayenne.query.InsertBatchQuery.getValue(InsertBatchQuery.java:61)
> 	at org.apache.cayenne.access.trans.InsertBatchQueryBuilder.getParameterValues(InsertBatchQueryBuilder.java:81)
> 	at org.apache.cayenne.access.jdbc.BatchAction.runAsIndividualQueries(BatchAction.java:212)
> 	at org.apache.cayenne.access.jdbc.BatchAction.performAction(BatchAction.java:91)
> 	at org.apache.cayenne.access.DataNodeQueryAction.runQuery(DataNodeQueryAction.java:87)
> 	at org.apache.cayenne.access.DataNode.performQueries(DataNode.java:269)
> 	at org.apache.cayenne.access.DataDomainFlushAction.runQueries(DataDomainFlushAction.java:226)
> 	at org.apache.cayenne.access.DataDomainFlushAction.flush(DataDomainFlushAction.java:144)
> 	at org.apache.cayenne.access.DataDomain.onSyncFlush(DataDomain.java:824)
> 	at org.apache.cayenne.access.DataDomain$2.transform(DataDomain.java:791)
> 	at org.apache.cayenne.access.DataDomain.runInTransaction(DataDomain.java:850)
> 	at org.apache.cayenne.access.DataDomain.onSync(DataDomain.java:788)
> 	at org.apache.cayenne.access.DataContext.flushToParent(DataContext.java:1106)
> 	at org.apache.cayenne.access.DataContext.commitChanges(DataContext.java:1045)
> [...]
> Thomas

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira