Indeed I forgot to add a datanode :( Thank you. imo it would be good to make a note (jira issue?) for us to catch that error earlier in cayenne before it becomes a NullPointerException, so it can be thrown with a meaningful message like "You haven't even created a data node. What on earth are you THINKING?!" :)
On Fri, Aug 26, 2011 at 10:36 AM, Andrus Adamchik <[email protected]>wrote: > I think the reason is that you haven't mapped and DataNodes (at least > cayenne.xml doesn't have any). DataNode is an abstraction of a DB connection > pool. E.g. see > > > http://cayenne.apache.org/doc30/tutorial-starting-project.data/base-datanode.png > > which is a part of the Cayenne tutorial at > http://cayenne.apache.org/doc30/tutorial-starting-project.html > > Andrus > > On Aug 26, 2011, at 6:32 PM, Joel Becker wrote: > > > 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 > > <cayenne.xml><Exercise.map.xml> > >
