Implement undirectional One-To-One relationship in Datastore from Android client Google app engine

I have 2 entites - "UserMaster" and "FeedMaster" and they have follwoing structure :

UserMaster

  • userId
  • userName

FeedMaster

  • feedId
  • userId_fk (its foreign key which point to object of UserMaster entity)

For that i have designed entity classes as shown below. Is these classes proper for my requirement?

@Entity
public class FeedMaster {
@Id
    private String feedId;
@OneToOne
    @JoinColumn(name = "USER_ID")
    UserMaster user;

getter()
.........
setter()
}

@Entity
public class UserMaster {
@Id
private String userId;

    private String userName;

getter()
........
setter()
}

Server error log :

com.google.api.server.spi.SystemService invokeServiceMethod: Error in meta-data for field com.sampleregistrationapp.UserMaster.userId : Cannot have a primary key of type java.lang.String and be a child object (owning field is "com.sampleregistrationapp.FeedMaster.user").
Error in meta-data for field com.sampleregistrationapp.UserMaster.userId : Cannot have a primary key of type java.lang.String and be a child object (owning field is "com.sampleregistrationapp.FeedMaster.user").
org.datanucleus.metadata.InvalidMetaDataException: Error in meta-data for field com.sampleregistrationapp.UserMaster.userId : Cannot have a primary key of type java.lang.String and be a child object (owning field is "com.sampleregistrationapp.FeedMaster.user").
    at com.google.appengine.datanucleus.MetaDataValidator.checkForIllegalChildField(MetaDataValidator.java:400)
    at com.google.appengine.datanucleus.MetaDataValidator.validateField(MetaDataValidator.java:292)
    at com.google.appengine.datanucleus.MetaDataValidator.validate(MetaDataValidator.java:200)
    at com.google.appengine.datanucleus.DatastoreManager.validateMetaDataForClass(DatastoreManager.java:571)
    at com.google.appengine.datanucleus.DatastorePersistenceHandler.fetchObject(DatastorePersistenceHandler.java:534)
    at org.datanucleus.state.JDOStateManager.loadFieldsFromDatastore(JDOStateManager.java:1638)
    at org.datanucleus.state.JDOStateManager.validate(JDOStateManager.java:3511)
    at org.datanucleus.ObjectManagerImpl.findObject(ObjectManagerImpl.java:3379)
    at org.datanucleus.api.jpa.JPAEntityManager.find(JPAEntityManager.java:358)
    at org.datanucleus.api.jpa.JPAEntityManager.find(JPAEntityManager.java:256)
    at com.sampleregistrationapp.FeedMasterEndpoint.containsFeedMaster(FeedMasterEndpoint.java:161)
    at com.sampleregistrationapp.FeedMasterEndpoint.insertFeedMaster(FeedMasterEndpoint.java:105)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:45)
    at com.google.api.server.spi.SystemService.invokeServiceMethod(SystemService.java:359)
    at com.google.api.server.spi.SystemServiceServlet.execute(SystemServiceServlet.java:124)
    at com.google.api.server.spi.SystemServiceServlet.doPost(SystemServiceServlet.java:82)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
    at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
    at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
    at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
    at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    at org.mortbay.jetty.Server.handle(Server.java:326)
    at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
    at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:923)
    at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
    at com.google.tracing.TraceContext$TraceContextRunnable.runInContext(TraceContext.java:437)
    at com.google.tracing.TraceContext$TraceContextRunnable$1.run(TraceContext.java:444)
    at com.google.tracing.CurrentContext.runInContext(CurrentContext.java:188)
    at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContextNoUnref(TraceContext.java:308)
    at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContext(TraceContext.java:300)
    at com.google.tracing.TraceContext$TraceContextRunnable.run(TraceContext.java:441)
    at java.lang.Thread.run(Thread.java:724)

Answers


I solved this issue. I came to know that if we define any object as child object in another entity then that child entity must use Key class to set its identity column. So i changed my coding ass follow and now its working properly.I am using it from android client.

UserMaster :

@Entity
public class UserMaster {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Key key;    
    private String userName;

    getter()...setter()
}

FeedMaster:

@Entity
public class FeedMaster {
    @Id
    private String feedId;
    @OneToOne(cascade = CascadeType.ALL)
    UserMaster user;

    getter()...setter()
}

Android client :

Usermasterendpoint.Builder userBuilder = new Usermasterendpoint.Builder(
AndroidHttp.newCompatibleTransport(),new JacksonFactory(), new HttpRequestInitializer()
                        {
                public void initialize(HttpRequest arg0)throws IOException {
                }
                });
Usermasterendpoint userEndpoint = CloudEndpointUtils.updateBuilder(userBuilder).build();
UserMaster user = userEndpoint.getUserByName(userID).execute();
Feedmasterendpoint.Builder builder = new Feedmasterendpoint.Builder(
      AndroidHttp.newCompatibleTransport(), new JacksonFactory(), 
      new HttpRequestInitializer() {
            public void initialize(HttpRequest arg0)throws IOException {
            }
      });
Feedmasterendpoint endpoint = CloudEndpointUtils.updateBuilder(builder).build();
FeedMaster objFeed = new FeedMaster();
objFeed.setFeedId(userID + new Data().toString());
objFeed.setUser(user);
endpoint.insertFeedMaster(objFeed).execute();

Need Your Help

Display a set of Images from a folder on Web2py

python database image web2py

I am a web2py newbie and I have the following doubt.

Exporting android project to jar (that includes other jars)

java android jar

I've written a Android Game Engine library and would like to export it to a jar file. I've tried to do this with the following: