cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Dzmitry Kazimirchyk (JIRA)" <>
Subject [jira] [Updated] (CAY-1444) NPE when persisting a newly instatiated object
Date Tue, 05 Apr 2011 07:50:06 GMT


Dzmitry Kazimirchyk updated CAY-1444:

    Attachment: cay-1444.patch

Maybe we can do the check at DataDomainInsertBucket. I think if we doing insert action even
if there is no changes to default values we should create an empty changes map.
Also added unit test for this issue.

> NPE when persisting a newly instatiated object
> ----------------------------------------------
>                 Key: CAY-1444
>                 URL:
>             Project: Cayenne
>          Issue Type: Bug
>          Components: Core Library
>    Affects Versions: 3.0
>            Reporter: Thomas Lopatic
>            Priority: Minor
>         Attachments: cay-1444.patch, 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
> <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"
> <obj-relationship name="settingsUser" source="Settings" target="User" deleteRule="Nullify"
> <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
> 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(
> 	at org.apache.cayenne.query.InsertBatchQuery.getValue(
> 	at org.apache.cayenne.access.trans.InsertBatchQueryBuilder.getParameterValues(
> 	at org.apache.cayenne.access.jdbc.BatchAction.runAsIndividualQueries(
> 	at org.apache.cayenne.access.jdbc.BatchAction.performAction(
> 	at org.apache.cayenne.access.DataNodeQueryAction.runQuery(
> 	at org.apache.cayenne.access.DataNode.performQueries(
> 	at org.apache.cayenne.access.DataDomainFlushAction.runQueries(
> 	at org.apache.cayenne.access.DataDomainFlushAction.flush(
> 	at org.apache.cayenne.access.DataDomain.onSyncFlush(
> 	at org.apache.cayenne.access.DataDomain$2.transform(
> 	at org.apache.cayenne.access.DataDomain.runInTransaction(
> 	at org.apache.cayenne.access.DataDomain.onSync(
> 	at org.apache.cayenne.access.DataContext.flushToParent(
> 	at org.apache.cayenne.access.DataContext.commitChanges(
> [...]
> Thomas

This message is automatically generated by JIRA.
For more information on JIRA, see:

View raw message