The code below correctly adds a 'Project' object which contains one child 'Div' object to a mysql database. However, the final line creates a null pointer exception, as although the database is persisted correctly, the relation has not been added to the java object.
ServerRuntime cayenneRuntime = new ServerRuntime("cayenne-BlueTwine.xml"); ObjectContext context = cayenneRuntime.getContext(); Project project = context.newObject(Project.class); // Add new project to context // set some variables on project object Div rootDiv = context.newObject(Div.class); // set some variables on rootDiv object rootDiv.setProject(project); context.commitChanges(); System.out.println(rootDiv.getProject().getId()); // Returns null pointer
When I last worked on this project a year ago, the above code would execute correctly, so I know that this is possible. Could upgrading to apache cayenne 3.1 have affected anything? Since upgrading I have synced my classes with the database schema, regenerated my classes, and rebuilt my database schema.
Any suggestions on why this relation has not been added to the java object would be greatly appreciated, as I'm stuck for where to look!