Hello. In my app I create an ObjectContext, create some domain objects, and
call commitChanges(), which causes a NullPointerException with the following
stack trace:

Exception in thread "main" org.apache.cayenne.CayenneRuntimeException:
[v.3.0.1 Sep 06 2010 15:09:38] Commit Exception
        at
org.apache.cayenne.access.DataContext.flushToParent(DataContext.java:1134)
        at
org.apache.cayenne.access.DataContext.commitChanges(DataContext.java:1045)
        at net.joelbecker.exercise.App.main(App.java:50)
Caused by: java.lang.NullPointerException
        at
org.apache.cayenne.access.DataDomainInsertBucket.createPermIds(DataDomainInsertBucket.java:101)
        at
org.apache.cayenne.access.DataDomainInsertBucket.appendQueriesInternal(DataDomainInsertBucket.java:76)
        at
org.apache.cayenne.access.DataDomainSyncBucket.appendQueries(DataDomainSyncBucket.java:79)
        at
org.apache.cayenne.access.DataDomainFlushAction.preprocess(DataDomainFlushAction.java:182)
        at
org.apache.cayenne.access.DataDomainFlushAction.flush(DataDomainFlushAction.java:134)
        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)
        ... 2 more

I created from scratch a data model in Cayenne Modeler, and generated the
java files from there into a maven project which also includes the
cayenne.xml and map files in src/main/resources, and App.java in
src/main/java/<package>. I attached all of my files. I'm using modeller
3.0.2 and library version 3.0.1.

I debugged into the Cayenne code for a while and found that the reason the
NPE occurs at DataDomainInsertBucket:101 because node is null because
parent.getDomain().lookupDataNode("Exercise") returns null because
DataDomain.nodesByDataMapName is empty. I traced the map file loading code
for a while but haven't figured out where nodesByDataMapName is populated
and why it is not being populated (my breakpoint at the first line of
DataDomain.addNode() never hits). Has anyone seen this before, or has an
idea why it occurs?

Thanks.
-Joel
<?xml version="1.0" encoding="utf-8"?>
<domains project-version="3.0.0.1">
<domain name="Exercise">
	<map name="Exercise" location="Exercise.map.xml"/>
</domain>
</domains>
<?xml version="1.0" encoding="utf-8"?>
<data-map xmlns="http://cayenne.apache.org/schema/3.0/modelMap";
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
  xsi:schemaLocation="http://cayenne.apache.org/schema/3.0/modelMap http://cayenne.apache.org/schema/3.0/modelMap.xsd";
  project-version="3.0.0.1">
	<property name="defaultPackage" value="net.joelbecker.exercise.model"/>
	<db-entity name="EXERCISE">
		<db-attribute name="abbrev" type="VARCHAR" isMandatory="true" length="8"/>
		<db-attribute name="id" type="INTEGER" isPrimaryKey="true" isMandatory="true"/>
		<db-attribute name="muscleGroup" type="INTEGER" isMandatory="true"/>
		<db-attribute name="name" type="VARCHAR" isMandatory="true" length="80"/>
		<db-attribute name="notes" type="VARCHAR" length="256"/>
	</db-entity>
	<db-entity name="SET">
		<db-attribute name="exercise_id" type="INTEGER" isMandatory="true"/>
		<db-attribute name="id" type="INTEGER" isPrimaryKey="true" isMandatory="true"/>
		<db-attribute name="notes" type="VARCHAR" length="256"/>
		<db-attribute name="repetitions" type="INTEGER" isMandatory="true"/>
		<db-attribute name="time" type="TIMESTAMP" isMandatory="true"/>
		<db-attribute name="user_id" type="INTEGER" isMandatory="true"/>
		<db-attribute name="weight" type="FLOAT" isMandatory="true"/>
	</db-entity>
	<db-entity name="USER">
		<db-attribute name="birthDate" type="TIMESTAMP" isMandatory="true"/>
		<db-attribute name="firstName" type="VARCHAR" isMandatory="true" length="40"/>
		<db-attribute name="id" type="INTEGER" isPrimaryKey="true" isMandatory="true"/>
		<db-attribute name="lastName" type="VARCHAR" isMandatory="true" length="40"/>
	</db-entity>
	<db-entity name="USER_EXERCISE">
		<db-attribute name="exercise_id" type="VARCHAR" isPrimaryKey="true" isMandatory="true" length="80"/>
		<db-attribute name="user_id" type="INTEGER" isPrimaryKey="true" isMandatory="true"/>
	</db-entity>
	<obj-entity name="Exercise" className="net.joelbecker.exercise.model.Exercise" dbEntityName="EXERCISE">
		<obj-attribute name="abbrev" type="java.lang.String" db-attribute-path="abbrev"/>
		<obj-attribute name="muscleGroup" type="java.lang.Integer" db-attribute-path="muscleGroup"/>
		<obj-attribute name="name" type="java.lang.String" db-attribute-path="name"/>
		<obj-attribute name="notes" type="java.lang.String" db-attribute-path="notes"/>
	</obj-entity>
	<obj-entity name="Set" className="net.joelbecker.exercise.model.Set" dbEntityName="SET">
		<obj-attribute name="notes" type="java.lang.String" db-attribute-path="notes"/>
		<obj-attribute name="repetitions" type="java.lang.Integer" db-attribute-path="repetitions"/>
		<obj-attribute name="time" type="java.util.Date" db-attribute-path="time"/>
		<obj-attribute name="weight" type="java.lang.Float" db-attribute-path="weight"/>
	</obj-entity>
	<obj-entity name="User" className="net.joelbecker.exercise.model.User" dbEntityName="USER">
		<obj-attribute name="birthDate" type="java.util.Date" db-attribute-path="birthDate"/>
		<obj-attribute name="firstName" type="java.lang.String" db-attribute-path="firstName"/>
		<obj-attribute name="lastName" type="java.lang.String" db-attribute-path="lastName"/>
	</obj-entity>
	<db-relationship name="exerciseUsers" source="EXERCISE" target="USER_EXERCISE" toMany="true">
		<db-attribute-pair source="name" target="exercise_id"/>
	</db-relationship>
	<db-relationship name="sets" source="EXERCISE" target="SET" toMany="true">
		<db-attribute-pair source="name" target="exercise_id"/>
	</db-relationship>
	<db-relationship name="users" source="EXERCISE" target="USER_EXERCISE" toMany="true">
		<db-attribute-pair source="name" target="exercise_id"/>
	</db-relationship>
	<db-relationship name="exercise" source="SET" target="EXERCISE" toMany="false">
		<db-attribute-pair source="exercise_id" target="name"/>
	</db-relationship>
	<db-relationship name="user" source="SET" target="USER" toMany="false">
		<db-attribute-pair source="user_id" target="id"/>
	</db-relationship>
	<db-relationship name="exercises" source="USER" target="USER_EXERCISE" toDependentPK="true" toMany="true">
		<db-attribute-pair source="id" target="user_id"/>
	</db-relationship>
	<db-relationship name="sets" source="USER" target="SET" toMany="true">
		<db-attribute-pair source="id" target="user_id"/>
	</db-relationship>
	<db-relationship name="userExercises" source="USER" target="USER_EXERCISE" toDependentPK="true" toMany="true">
		<db-attribute-pair source="id" target="user_id"/>
	</db-relationship>
	<db-relationship name="exerciseUsers" source="USER_EXERCISE" target="USER" toMany="false">
		<db-attribute-pair source="user_id" target="id"/>
	</db-relationship>
	<db-relationship name="userExercises" source="USER_EXERCISE" target="EXERCISE" toMany="false">
		<db-attribute-pair source="exercise_id" target="name"/>
	</db-relationship>
	<obj-relationship name="sets" source="Exercise" target="Set" deleteRule="Deny" db-relationship-path="sets"/>
	<obj-relationship name="users" source="Exercise" target="User" deleteRule="Deny" db-relationship-path="users.exerciseUsers"/>
	<obj-relationship name="exercise" source="Set" target="Exercise" deleteRule="Nullify" db-relationship-path="exercise"/>
	<obj-relationship name="user" source="Set" target="User" deleteRule="Nullify" db-relationship-path="user"/>
	<obj-relationship name="exercises" source="User" target="Exercise" deleteRule="Deny" db-relationship-path="exercises.userExercises"/>
	<obj-relationship name="sets" source="User" target="Set" deleteRule="Deny" db-relationship-path="sets"/>
</data-map>

Reply via email to