Hi Jake, thanks a lot for your answer.
After changing the mappedBy statement to child like this: @Persistent(mappedBy = "mOfferDetails") private Offer mOffer; and removing mappedBy from parent, Offer object seems to be persisted. But when I get this object from the database with: public Offer getOfferWithId (long id) { return pm.getObjectById(Offer.class, id); } and try to access child with System.out.printf(String.format ("Title %s", mOffer.getOfferDetails().getOfferDescription() )); I get following error: java.lang.NullPointerException at com.sparradar.server.action.actioncommands.ShowOfferDetailsActionCommand.execute(ShowOfferDetailsActionCommand.java: 41) at info.rk.vaadinapp.manager.urldispatching.URLActionDispatcher.handleURI(URLActionDispatcher.java: 90) at com.vaadin.ui.Window.handleURI(Window.java:358) at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.handleURI(AbstractCommunicationManager.java: 1830) at com.vaadin.terminal.gwt.server.CommunicationManager.handleURI(CommunicationManager.java: 311) at com.vaadin.terminal.gwt.server.AbstractApplicationServlet.handleURI(AbstractApplicationServlet.java: 912) at com.vaadin.terminal.gwt.server.AbstractApplicationServlet.service(AbstractApplicationServlet.java: 471) at com.vaadin.terminal.gwt.server.GAEApplicationServlet.service(GAEApplicationServlet.java: 231) at javax.servlet.http.HttpServlet.service(HttpServlet.java:806) at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java: 487) at org.mortbay.jetty.servlet.ServletHandler $CachedChain.doFilter(ServletHandler.java:1093) at com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java: 51) at org.mortbay.jetty.servlet.ServletHandler $CachedChain.doFilter(ServletHandler.java:1084) at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java: 43) at org.mortbay.jetty.servlet.ServletHandler $CachedChain.doFilter(ServletHandler.java:1084) at com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java: 121) at org.mortbay.jetty.servlet.ServletHandler $CachedChain.doFilter(ServletHandler.java:1084) at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java: 360) at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java: 216) at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java: 181) at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java: 712) at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java: 405) at com.google.apphosting.utils.jetty.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java: 70) at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java: 139) at com.google.appengine.tools.development.JettyContainerService $ApiProxyHandler.handle(JettyContainerService.java:352) at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java: 139) at org.mortbay.jetty.Server.handle(Server.java:313) at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java: 506) at org.mortbay.jetty.HttpConnection $RequestHandler.headerComplete(HttpConnection.java:830) at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:514) at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211) at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:381) at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java: 396) at org.mortbay.thread.BoundedThreadPool $PoolThread.run(BoundedThreadPool.java:442) I don't get the error if I try to access eg mOffer.getId(). So my interpretation of this error is that either the child object was not saved in the database, or it was not fetched from the database. I don't know how to verify this. Thanks, Anton On 24 Feb., 20:17, Jake <jbrooko...@cast.org> wrote: > http://code.google.com/appengine/docs/java/datastore/relationships.ht... > > "You create a bidirectional one-to-one relationship using fields on > both classes, with an annotation on the child class's field to declare > that the fields represent a bidirectional relationship. The field of > the child class must have a @Persistent annotation with the argument > mappedBy = "...", where the value is the name of the field on the > parent class." > > From what I see, you have it backwards, with the annotation in the > parent class. > > Jake > > On Feb 24, 4:26 am, Anton Klotz <dipl.ing.akl...@googlemail.com> > wrote: > > > > > Hi, > > > could please somebody tell me, what I'm doing wrong here? > > > Here is one child datastructure I want to persist: > > > @PersistenceCapable > > > public class OfferDetails { > > > @PrimaryKey > > @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY) > > private Key mId; > > > @Persistent > > private String mOfferDescription; > > > @Persistent > > private Offer mOffer; > > > public OfferDetails () > > { > > > } > > > public OfferDetails (String offerDesc) > > { > > this (); > > mOfferDescription = offerDesc; > > } > > > } > > > And here is the parent > > > @PersistenceCapable(identityType = IdentityType.APPLICATION, > > detachable="true") > > > public class Offer { > > @PrimaryKey > > @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY) > > private Key mId; > > > @Persistent(mappedBy="mOffer") > > private OfferDetails mOfferDetails; > > > public Offer( OfferDetails offerDetails) > > { > > this(); > > mOfferDetails = offerDetails; > > } > > > } > > > Here is the presistance routine: > > > public class OfferDataAccess { > > private static final long serialVersionUID = > > -7037344095742126014L; > > private PersistenceManager pm; > > > public OfferDataAccess () > > { > > pm = PMF.get().getPersistenceManager(); > > } > > > public void persistOffer (Offer offer) > > { > > pm.currentTransaction().begin(); > > try { > > pm.makePersistent(offer); > > pm.currentTransaction().commit(); > > } finally { > > if (pm.currentTransaction().isActive()) > > pm.currentTransaction().rollback(); > > pm.close(); > > } > > } > > > And here is the call of the persistance routine: > > class CreateOfferActionCommand > > { > > public void execute() { > > mOfferDB = new OfferDataAccess (); > > mOffer = new Offer (mOfferDetails); > > mOfferDB.persistOffer (mOffer); > > > } > > } > > > Now if I run this code, I get following errormessage: > > > java.lang.IllegalStateException: Primary key for object of type > > OfferDetails is null. > > at > > org.datanucleus.store.appengine.EntityUtils.getPkAsKey(EntityUtils.java: > > 152) > > at > > org.datanucleus.store.appengine.DatastoreFieldManager.getKeyForObject(Datas > > toreFieldManager.java: > > 625) > > at > > org.datanucleus.store.appengine.DatastoreFieldManager.getParentKeyFromParen > > tField(DatastoreFieldManager.java: > > 634) > > at > > org.datanucleus.store.appengine.DatastoreFieldManager.establishEntityGroup( > > DatastoreFieldManager.java: > > 591) > > at > > org.datanucleus.store.appengine.DatastorePersistenceHandler.insertPreProces > > s(DatastorePersistenceHandler.java: > > 338) > > at > > org.datanucleus.store.appengine.DatastorePersistenceHandler.insertObjects(D > > atastorePersistenceHandler.java: > > 246) > > at > > org.datanucleus.store.appengine.DatastorePersistenceHandler.insertObject(Da > > tastorePersistenceHandler.java: > > 235) > > at > > org.datanucleus.state.JDOStateManagerImpl.internalMakePersistent(JDOStateMa > > nagerImpl.java: > > 3185) > > at > > org.datanucleus.state.JDOStateManagerImpl.makePersistent(JDOStateManagerImp > > l.java: > > 3161) > > at > > org.datanucleus.ObjectManagerImpl.persistObjectInternal(ObjectManagerImpl.j > > ava: > > 1298) > > at > > org.datanucleus.ObjectManagerImpl.persistObject(ObjectManagerImpl.java: > > 1175) > > at > > org.datanucleus.jdo.JDOPersistenceManager.jdoMakePersistent(JDOPersistenceM > > anager.java: > > 669) > > at > > org.datanucleus.jdo.JDOPersistenceManager.makePersistent(JDOPersistenceMana > > ger.java: > > 694) > > at > > com.sparradar.server.datamodel.offer.OfferDataAccess.persistOffer(OfferData > > Access.java: > > 29) > > at > > com.sparradar.server.action.actioncommands.CreateOfferActionCommand.execute > > (CreateOfferActionCommand.java: > > 60) > > at > > info.rk.vaadinapp.manager.urldispatching.URLActionDispatcher.handleURI(URLA > > ctionDispatcher.java: > > 90) > > at com.vaadin.ui.Window.handleURI(Window.java:358) > > at > > com.vaadin.terminal.gwt.server.AbstractCommunicationManager.handleURI(Abstr > > actCommunicationManager.java: > > 1830) > > at > > com.vaadin.terminal.gwt.server.CommunicationManager.handleURI(Communication > > Manager.java: > > 311) > > at > > com.vaadin.terminal.gwt.server.AbstractApplicationServlet.handleURI(Abstrac > > tApplicationServlet.java: > > 912) > > at > > com.vaadin.terminal.gwt.server.AbstractApplicationServlet.service(AbstractA > > pplicationServlet.java: > > 471) > > at > > com.vaadin.terminal.gwt.server.GAEApplicationServlet.service(GAEApplication > > Servlet.java: > > 231) > > at javax.servlet.http.HttpServlet.service(HttpServlet.java:806) > > at > > org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java: > > 487) > > at org.mortbay.jetty.servlet.ServletHandler > > $CachedChain.doFilter(ServletHandler.java:1093) > > at > > com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFi > > lter.java: > > 51) > > at org.mortbay.jetty.servlet.ServletHandler > > $CachedChain.doFilter(ServletHandler.java:1084) > > at > > com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(Trans > > actionCleanupFilter.java: > > 43) > > at org.mortbay.jetty.servlet.ServletHandler > > $CachedChain.doFilter(ServletHandler.java:1084) > > at > > com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFile > > Filter.java: > > 121) > > at org.mortbay.jetty.servlet.ServletHandler > > $CachedChain.doFilter(ServletHandler.java:1084) > > at > > org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java: > > 360) > > at > > org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java: > > 216) > > at > > org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java: > > 181) > > at > > org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java: > > 712) > > at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java: > > 405) > > at > > com.google.apphosting.utils.jetty.DevAppEngineWebAppContext.handle(DevAppEn > > gineWebAppContext.java: > > 70) > > at > > org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java: > > 139) > > at com.google.appengine.tools.development.JettyContainerService > > $ApiProxyHandler.handle(JettyContainerService.java:352) > > at > > org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java: > > 139) > > at org.mortbay.jetty.Server.handle(Server.java:313) > > at > > org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java: > > 506) > > at org.mortbay.jetty.HttpConnection > > $RequestHandler.headerComplete(HttpConnection.java:830) > > at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:514) > > at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211) > > at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:381) > > at > > org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java: > > 396) > > at org.mortbay.thread.BoundedThreadPool > > $PoolThread.run(BoundedThreadPool.java:442) > > > Could you please tell me, what I'm doing wrong here? -- You received this message because you are subscribed to the Google Groups "Google App Engine for Java" group. To post to this group, send email to google-appengine-j...@googlegroups.com. To unsubscribe from this group, send email to google-appengine-java+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-appengine-java?hl=en.