google cloud datastore - Child entity identity (crisis) in JPA and app-engine -


i have 2 models: author , book, author may have list of books. start author has long @id , book has string @id.

when try put data datastore, error cannot have java.lang.string primary key , child object (owning field …. after searching online, landed on persist list of objects. there decided use, within book class,

@primarykey @persistent(valuestrategy = idgeneratorstrategy.identity) private key key; 

and in constructor, do

key key = keyfactory.createkey(book.class.getsimplename(), bookcode); this.key = key; // same calling bookobject.setkey(key) 

so getting new error

class book has application-identity , no objectid-class specified yet has 0 primary key fields. unable use singlefieldidentity. 

will please provide code snippet rectify problem? or @ least specific guidance?

edit code:

@entity public class book{    @primarykey    @persistent(valuestrategy = idgeneratorstrategy.identity)    private key key;     private string title;     //other fields     //getters , setters follow  }  @entity public class author{    @id    private long ssn;     private string firstname;     private string lastname;     list<book> books;     //getters , setters follow } 

edit add stack trace:

java.lang.exceptionininitializererror     @ java.lang.class.forname0(native method)     @ java.lang.class.forname(class.java:169)     @ com.google.appengine.tools.development.agent.runtime.runtimehelper.checkrestricted(runtimehelper.java:70)     @ com.google.appengine.tools.development.agent.runtime.runtime.checkrestricted(runtime.java:64)     @ com.friends.bookclub.dao.impl.genericdaoimpl.getentitymanager(genericdaoimpl.java:82)     @ com.friends.bookclub.dao.impl.genericdaoimpl.put(genericdaoimpl.java:45)     @ com.friends.bookclub.bookclubapi.registeruser(bookclubapi.java:76)     @ sun.reflect.nativemethodaccessorimpl.invoke0(native method)     @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:39)     @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:25)     @ java.lang.reflect.method.invoke(method.java:597)     @ com.google.appengine.tools.development.agent.runtime.runtime.invoke(runtime.java:115)     @ com.google.api.server.spi.systemservice.invokeservicemethod(systemservice.java:304)     @ com.google.api.server.spi.systemserviceservlet.execute(systemserviceservlet.java:161)     @ com.google.api.server.spi.systemserviceservlet.dopost(systemserviceservlet.java:120)     @ javax.servlet.http.httpservlet.service(httpservlet.java:637)     @ javax.servlet.http.httpservlet.service(httpservlet.java:717)     @ org.mortbay.jetty.servlet.servletholder.handle(servletholder.java:511)     @ org.mortbay.jetty.servlet.servlethandler$cachedchain.dofilter(servlethandler.java:1166)     @ com.google.appengine.api.socket.dev.devsocketfilter.dofilter(devsocketfilter.java:74)     @ org.mortbay.jetty.servlet.servlethandler$cachedchain.dofilter(servlethandler.java:1157)     @ com.google.appengine.tools.development.responserewriterfilter.dofilter(responserewriterfilter.java:123)     @ org.mortbay.jetty.servlet.servlethandler$cachedchain.dofilter(servlethandler.java:1157)     @ com.google.appengine.tools.development.headerverificationfilter.dofilter(headerverificationfilter.java:34)     @ org.mortbay.jetty.servlet.servlethandler$cachedchain.dofilter(servlethandler.java:1157)     @ com.google.appengine.api.blobstore.dev.serveblobfilter.dofilter(serveblobfilter.java:61)     @ org.mortbay.jetty.servlet.servlethandler$cachedchain.dofilter(servlethandler.java:1157)     @ com.google.apphosting.utils.servlet.transactioncleanupfilter.dofilter(transactioncleanupfilter.java:43)     @ org.mortbay.jetty.servlet.servlethandler$cachedchain.dofilter(servlethandler.java:1157)     @ com.google.appengine.tools.development.staticfilefilter.dofilter(staticfilefilter.java:125)     @ org.mortbay.jetty.servlet.servlethandler$cachedchain.dofilter(servlethandler.java:1157)     @ com.google.appengine.tools.development.devappserverserversfilter.dofilter(devappserverserversfilter.java:106)     @ org.mortbay.jetty.servlet.servlethandler$cachedchain.dofilter(servlethandler.java:1157)     @ org.mortbay.jetty.servlet.servlethandler.handle(servlethandler.java:388)     @ org.mortbay.jetty.security.securityhandler.handle(securityhandler.java:216)     @ org.mortbay.jetty.servlet.sessionhandler.handle(sessionhandler.java:182)     @ org.mortbay.jetty.handler.contexthandler.handle(contexthandler.java:765)     @ org.mortbay.jetty.webapp.webappcontext.handle(webappcontext.java:418)     @ com.google.appengine.tools.development.devappenginewebappcontext.handle(devappenginewebappcontext.java:94)     @ org.mortbay.jetty.handler.handlerwrapper.handle(handlerwrapper.java:152)     @ com.google.appengine.tools.development.jettycontainerservice$apiproxyhandler.handle(jettycontainerservice.java:421)     @ org.mortbay.jetty.handler.handlerwrapper.handle(handlerwrapper.java:152)     @ org.mortbay.jetty.server.handle(server.java:326)     @ org.mortbay.jetty.httpconnection.handlerequest(httpconnection.java:542)     @ org.mortbay.jetty.httpconnection$requesthandler.content(httpconnection.java:938)     @ org.mortbay.jetty.httpparser.parsenext(httpparser.java:755)     @ org.mortbay.jetty.httpparser.parseavailable(httpparser.java:218)     @ org.mortbay.jetty.httpconnection.handle(httpconnection.java:404)     @ org.mortbay.io.nio.selectchannelendpoint.run(selectchannelendpoint.java:409)     @ org.mortbay.thread.queuedthreadpool$poolthread.run(queuedthreadpool.java:582) caused by: javax.persistence.persistenceexception: explicit persistence provider error(s) occurred "transactions-optional" after trying following discovered implementations: org.datanucleus.api.jpa.persistenceproviderimpl provider: org.datanucleus.api.jpa.persistenceproviderimpl     @ javax.persistence.persistence.createpersistenceexception(persistence.java:242)     @ javax.persistence.persistence.createentitymanagerfactory(persistence.java:184)     @ javax.persistence.persistence.createentitymanagerfactory(persistence.java:70)     @ com.friends.bookclub.domain.utils.emf.<clinit>(emf.java:8)     ... 50 more caused by: org.datanucleus.metadata.invalidclassmetadataexception: class com.friends.bookclub.db.book has application-identity , no objectid-class specified yet has 0 primary key fields. unable use singlefieldidentity.     @ org.datanucleus.metadata.abstractclassmetadata.determineobjectidclass(abstractclassmetadata.java:1355)     @ org.datanucleus.metadata.classmetadata.populate(classmetadata.java:209)     @ org.datanucleus.metadata.metadatamanager$1.run(metadatamanager.java:2699)     @ java.security.accesscontroller.doprivileged(native method)     @ org.datanucleus.metadata.metadatamanager.populateabstractclassmetadata(metadatamanager.java:2693)     @ org.datanucleus.metadata.metadatamanager.populatefilemetadata(metadatamanager.java:2516)     @ org.datanucleus.metadata.metadatamanager.initialisefilemetadataforuse(metadatamanager.java:1123)     @ org.datanucleus.metadata.metadatamanager.loadpersistenceunit(metadatamanager.java:986)     @ org.datanucleus.api.jpa.jpaentitymanagerfactory.initialisenucleuscontext(jpaentitymanagerfactory.java:754)     @ org.datanucleus.api.jpa.jpaentitymanagerfactory.initialise(jpaentitymanagerfactory.java:417)     @ org.datanucleus.api.jpa.jpaentitymanagerfactory.<init>(jpaentitymanagerfactory.java:380)     @ org.datanucleus.api.jpa.persistenceproviderimpl.createentitymanagerfactory(persistenceproviderimpl.java:91)     @ javax.persistence.persistence.createentitymanagerfactory(persistence.java:150)     ... 52 more apr 5, 2013 8:54:21 com.google.api.server.spi.systemservice invokeservicemethod severe: null java.lang.exceptionininitializererror     @ java.lang.class.forname0(native method)     @ java.lang.class.forname(class.java:169)     @ com.google.appengine.tools.development.agent.runtime.runtimehelper.checkrestricted(runtimehelper.java:70)     @ com.google.appengine.tools.development.agent.runtime.runtime.checkrestricted(runtime.java:64)     @ com.friends.bookclub.dao.impl.genericdaoimpl.getentitymanager(genericdaoimpl.java:82)     @ com.friends.bookclub.dao.impl.genericdaoimpl.put(genericdaoimpl.java:45)     @ com.friends.bookclub.bookclubapi.registeruser(bookclubapi.java:76)     @ sun.reflect.nativemethodaccessorimpl.invoke0(native method)     @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:39)     @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:25)     @ java.lang.reflect.method.invoke(method.java:597)     @ com.google.appengine.tools.development.agent.runtime.runtime.invoke(runtime.java:115)     @ com.google.api.server.spi.systemservice.invokeservicemethod(systemservice.java:304)     @ com.google.api.server.spi.systemserviceservlet.execute(systemserviceservlet.java:161)     @ com.google.api.server.spi.systemserviceservlet.dopost(systemserviceservlet.java:120)     @ javax.servlet.http.httpservlet.service(httpservlet.java:637)     @ javax.servlet.http.httpservlet.service(httpservlet.java:717)     @ org.mortbay.jetty.servlet.servletholder.handle(servletholder.java:511)     @ org.mortbay.jetty.servlet.servlethandler$cachedchain.dofilter(servlethandler.java:1166)     @ com.google.appengine.api.socket.dev.devsocketfilter.dofilter(devsocketfilter.java:74)     @ org.mortbay.jetty.servlet.servlethandler$cachedchain.dofilter(servlethandler.java:1157)     @ com.google.appengine.tools.development.responserewriterfilter.dofilter(responserewriterfilter.java:123)     @ org.mortbay.jetty.servlet.servlethandler$cachedchain.dofilter(servlethandler.java:1157)     @ com.google.appengine.tools.development.headerverificationfilter.dofilter(headerverificationfilter.java:34)     @ org.mortbay.jetty.servlet.servlethandler$cachedchain.dofilter(servlethandler.java:1157)     @ com.google.appengine.api.blobstore.dev.serveblobfilter.dofilter(serveblobfilter.java:61)     @ org.mortbay.jetty.servlet.servlethandler$cachedchain.dofilter(servlethandler.java:1157)     @ com.google.apphosting.utils.servlet.transactioncleanupfilter.dofilter(transactioncleanupfilter.java:43)     @ org.mortbay.jetty.servlet.servlethandler$cachedchain.dofilter(servlethandler.java:1157)     @ com.google.appengine.tools.development.staticfilefilter.dofilter(staticfilefilter.java:125)     @ org.mortbay.jetty.servlet.servlethandler$cachedchain.dofilter(servlethandler.java:1157)     @ com.google.appengine.tools.development.devappserverserversfilter.dofilter(devappserverserversfilter.java:106)     @ org.mortbay.jetty.servlet.servlethandler$cachedchain.dofilter(servlethandler.java:1157)     @ org.mortbay.jetty.servlet.servlethandler.handle(servlethandler.java:388)     @ org.mortbay.jetty.security.securityhandler.handle(securityhandler.java:216)     @ org.mortbay.jetty.servlet.sessionhandler.handle(sessionhandler.java:182)     @ org.mortbay.jetty.handler.contexthandler.handle(contexthandler.java:765)     @ org.mortbay.jetty.webapp.webappcontext.handle(webappcontext.java:418)     @ com.google.appengine.tools.development.devappenginewebappcontext.handle(devappenginewebappcontext.java:94)     @ org.mortbay.jetty.handler.handlerwrapper.handle(handlerwrapper.java:152)     @ com.google.appengine.tools.development.jettycontainerservice$apiproxyhandler.handle(jettycontainerservice.java:421)     @ org.mortbay.jetty.handler.handlerwrapper.handle(handlerwrapper.java:152)     @ org.mortbay.jetty.server.handle(server.java:326)     @ org.mortbay.jetty.httpconnection.handlerequest(httpconnection.java:542)     @ org.mortbay.jetty.httpconnection$requesthandler.content(httpconnection.java:938)     @ org.mortbay.jetty.httpparser.parsenext(httpparser.java:755)     @ org.mortbay.jetty.httpparser.parseavailable(httpparser.java:218)     @ org.mortbay.jetty.httpconnection.handle(httpconnection.java:404)     @ org.mortbay.io.nio.selectchannelendpoint.run(selectchannelendpoint.java:409)     @ org.mortbay.thread.queuedthreadpool$poolthread.run(queuedthreadpool.java:582) caused by: javax.persistence.persistenceexception: explicit persistence provider error(s) occurred "transactions-optional" after trying following discovered implementations: org.datanucleus.api.jpa.persistenceproviderimpl provider: org.datanucleus.api.jpa.persistenceproviderimpl     @ javax.persistence.persistence.createpersistenceexception(persistence.java:242)     @ javax.persistence.persistence.createentitymanagerfactory(persistence.java:184)     @ javax.persistence.persistence.createentitymanagerfactory(persistence.java:70)     @ com.friends.bookclub.domain.utils.emf.<clinit>(emf.java:8)     ... 50 more caused by: org.datanucleus.metadata.invalidclassmetadataexception: class com.friends.bookclub.db.book has application-identity , no objectid-class specified yet has 0 primary key fields. unable use singlefieldidentity.     @ org.datanucleus.metadata.abstractclassmetadata.determineobjectidclass(abstractclassmetadata.java:1355)     @ org.datanucleus.metadata.classmetadata.populate(classmetadata.java:209)     @ org.datanucleus.metadata.metadatamanager$1.run(metadatamanager.java:2699)     @ java.security.accesscontroller.doprivileged(native method)     @ org.datanucleus.metadata.metadatamanager.populateabstractclassmetadata(metadatamanager.java:2693)     @ org.datanucleus.metadata.metadatamanager.populatefilemetadata(metadatamanager.java:2516)     @ org.datanucleus.metadata.metadatamanager.initialisefilemetadataforuse(metadatamanager.java:1123)     @ org.datanucleus.metadata.metadatamanager.loadpersistenceunit(metadatamanager.java:986)     @ org.datanucleus.api.jpa.jpaentitymanagerfactory.initialisenucleuscontext(jpaentitymanagerfactory.java:754)     @ org.datanucleus.api.jpa.jpaentitymanagerfactory.initialise(jpaentitymanagerfactory.java:417)     @ org.datanucleus.api.jpa.jpaentitymanagerfactory.<init>(jpaentitymanagerfactory.java:380)     @ org.datanucleus.api.jpa.persistenceproviderimpl.createentitymanagerfactory(persistenceproviderimpl.java:91)     @ javax.persistence.persistence.createentitymanagerfactory(persistence.java:150)     ... 52 more 

i think problem related keys of book , author.

you may not solution , not best one. (short) experience dealing owned-relationships in gae datastore, i've been getting many errors related keys, ended doing following:

i use primary keys all classes:

@primarykey @persistent(valuestrategy = idgeneratorstrategy.identity) private key key; 

and let application create key completely, mean, don't try add application-created value key. have getter , setter key, don't in constructor.

if want have own id/code/key objects, add antoher attribute in class.

i know may "coward" solution, working better me now...

edit: said before not best approach, because key queries faster queries other fields, if have solution i'd appreciate well...


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -