In JDO, all fields without an annotation are persistent by default. If you
don't want your list of kiosks to be persistent, you'll have to add an
explicit annotation:

@NotPersistent
private List<Kiosk> kiosks

With your current code, you're setting an owned relationship between the two
types of entities, which explains the exception that you're seeing. If you
do want to persist the relationship between users and kiosks in the future,
you can do so using unowned relationships:

http://code.google.com/appengine/docs/java/datastore/relationships.html#Unowned_Relationships

- Jason

On Thu, Aug 27, 2009 at 2:03 AM, swprog <[email protected]> wrote:

>
> Hi,
>
> I have two entities called UserAccount and Kiosk. They have a mxn
> relationship.
> Below are the class definitions for these two entities.
>
> public class UserAccount implements JsonBean {
>
>        @PrimaryKey
>        @Persistent
>        private String userId;
>
>        // non-persistent derived fields
>        private List<Kiosk> kiosks;
> }
>
> public class Kiosk implements JsonBean {
>        @PrimaryKey
>    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
>        private Long kioskId;
>
>        //non-persistent derived fields
>        private List<PoolGroup> poolGroups;
>        private List<UserAccount> users;
> }
>
> I am using a separate table to maintain the relationship between the
> two entities.
>
> public class UserToKiosk {
>
>        @PrimaryKey
>    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
>        private Long UserToKioskId;
>        @Persistent
>        private String userId;
>        @Persistent
>        private Long kioskId;
> }
>
> When I try to save the userAccount object I am getting the following
> exception:
>
> javax.jdo.JDOUserException: Error in meta-data for
> org.lggi.samaanguru.entity.Kiosk.kioskId: Cannot have a java.lang.Long
> primary key and be a child object (owning field is
> org.lggi.samaanguru.entity.UserAccount.kiosks).
>        at
> org.datanucleus.jdo.NucleusJDOHelper.getJDOExceptionForNucleusException
> (NucleusJDOHelper.java:427)
>        at org.datanucleus.jdo.JDOPersistenceManager.jdoMakePersistent
> (JDOPersistenceManager.java:673)
>        at org.datanucleus.jdo.JDOPersistenceManager.makePersistent
> (JDOPersistenceManager.java:693)
>        at org.lggi.samaanguru.service.impl.AccountsServiceImpl.addAccount
> (AccountsServiceImpl.java:55)
>        at org.lggi.samaanguru.servlet.TestServlet.executeTestCase1
> (TestServlet.java:217)
>        at
> org.lggi.samaanguru.servlet.TestServlet.doGet(TestServlet.java:41)
>        at javax.servlet.http.HttpServlet.service(HttpServlet.java:693)
>        at org.lggi.samaanguru.servlet.JsonRestServlet.service
> (JsonRestServlet.java:89)
>        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.apphosting.utils.servlet.TransactionCleanupFilter.doFilter
> (TransactionCleanupFilter.java:43)
>        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:54)
>        at org.mortbay.jetty.handler.HandlerWrapper.handle
> (HandlerWrapper.java:139)
>        at com.google.appengine.tools.development.JettyContainerService
> $ApiProxyHandler.handle(JettyContainerService.java:306)
>        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)
>
> Even though, the list of kiosks in the UserAccount object is not
> persistent, JDO is treating this as an owned relationship. Why is
> that? I want JDO to ignore this list of kiosks completely. Any way to
> do that?
>
> Thanks,
> Juhee
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
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 [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to