Just do: partner.addToCustomers(customer);
You don't need to do both lines. How did you create partner and customer? Did you create partner in a DataContext or fetch it from the DB? Is customer created in the same DataContext as partner? mrg On Fri, Sep 18, 2009 at 3:59 AM, Jamie <[email protected]> wrote: > Hi Michael > > Thanks for the help. Next question. I have a one to many Partner -> Customer > relationship defined. > When creating a new customer, I try to setup the relationship as follows: > > partner.addToCustomers(customer); > customer.setPartner(partner); > > I get a NullPointer, even though customer and partner are not null. > > SEVERE: Servlet.service() for servlet jsp threw exception > java.lang.NullPointerException > at > org.apache.cayenne.CayenneDataObject.setReverseRelationship(CayenneDataObject.java:385) > at > org.apache.cayenne.CayenneDataObject.setToOneTarget(CayenneDataObject.java:339) > at com.stimulus.support.auto._Customer.setPartner(_Customer.java:97) > at > org.apache.jsp.customerdetail_jsp._jspService(customerdetail_jsp.java:94) > at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) > at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) > at > org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374) > at > org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342) > at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267) > at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) > at > org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) > at > org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) > at > org.apache.cayenne.conf.WebApplicationContextFilter.doFilter(WebApplicationContextFilter.java:91) > at > org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) > at > org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) > at > org.securityfilter.filter.SecurityFilter.doFilter(SecurityFilter.java:188) > at > org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) > at > org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) > at > org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) > at > org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) > at > org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128) > at > org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) > at > org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) > at > org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293) > at > org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849) > at > org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583) > at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454) > at java.lang.Thread.run(Thread.java:619) > > Any ideas? > > Jamie > > Michael Gentry wrote: >> >> When you create a brand new ObjEntity from a DBEntity, it propagates >> all attributes and relationships defined in the DBEntity except for >> the primary key (Cayenne Modeler assumes you don't need that exposed). >> Once you've created the ObjEntity, though, adding a new relationship >> to the DBEntity will not be automatically synced to the ObjEntity. >> You have to sync it manually (click the double-arrow icon in either >> the DBEntity or ObjEntity toolbar or use the Project menu or keyboard >> shortcut). I'm talking mainly about 3.0M6 since I no longer use the >> 2.x modeler and don't remember the exact specifics of how it behaves. >> >> mrg >> >> >> On Thu, Sep 17, 2009 at 3:46 AM, Jamie <[email protected]> wrote: >> >>> >>> Hi Everyone >>> >>> I am really struggling to use the Cayenne Modelling tool. It seems >>> whenever >>> I create an ObjectEntity from the DBEntity the relationships are not >>> always >>> propagated. This happens even when I follow the ARTIST tutorial. I tried >>> both Cayenne 3.0M6 and Cayenne 2.0.4 and the same behaviour is observed. >>> Is >>> this a known bug or am I likely doing something horribly wrong? >>> >>> Thank in advance >>> >>> >>> Jamie >>> >>> >>> >>> > >
