cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Thomas Lopatic (JIRA)" <>
Subject [jira] Created: (CAY-1444) NPE when persisting a newly instatiated object
Date Sat, 05 Jun 2010 20:23:55 GMT
NPE when persisting a newly instatiated object

                 Key: CAY-1444
             Project: Cayenne
          Issue Type: Bug
          Components: Core Library
    Affects Versions: 3.0
            Reporter: Thomas Lopatic
            Priority: Minor

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-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-relationship name="settingsCity" source="Settings" target="City" toMany="false">
  <db-attribute-pair source="idCity" target="id"/>

<db-relationship name="settingsUser" source="Settings" target="User" toMany="false">
  <db-attribute-pair source="idUser" target="id"/>

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.
	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(


This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

View raw message