问题描述:

I'm new to JDO/Google Cloud Endpoints/App Engine and have been struggling a bit with storage and retrieval.

I have two classes: Message and User. Messages contain two Users, and Users contain a name and an email address.

Using the Eclipse Google Plugin, I run the appserver locally and use Javascript (based on the example) to insert a Message, along with two new Users in one request.

The problem comes in when I request the list of Messages from the server. I expect it to contain the full JSON for both the Messages as well as the users. However, if I create a new Message/User(s) and immediately invoke listMessage (generated function), the response only includes the key for the Users (Example 1). This continues for any Message/User I create during that run of the appserver.

If I stop the appserver and restart, I get the full set of values (Example 2, note the presence of keyId, name, and emailAddress). This continues for each subsequent request.

Have I defined something incorrectly? Why would I not get the same response for both cases?

Example 1:

 { // response directly after insertion

"id" : "4785074604081152",

"from" : {

"key" : "ag9waWdsZXRtYWlsLTEyNTFyEQsSBFVzZXIYgICAgICAwAkM"

},

"to" : {

"key" : "ag9waWdsZXRtYWlsLTEyNTFyEQsSBFVzZXIYgICAgICAwAoM"

},

"message" : "msg31",

"sent" : "2008-09-08T22:47:31-07:00"

}

Example 2:

 { // response when the appserver is restarted after insertion

"id" : "5629499534213120",

"from" : {

"key" : "ag9waWdsZXRtYWlsLTEyNTFyEQsSBFVzZXIYgICAgICAgAsM",

"keyId" : "6192449487634432",

"name" : "from",

"emailAddress" : "from"

},

"to" : {

"key" : "ag9waWdsZXRtYWlsLTEyNTFyEQsSBFVzZXIYgICAgICAgAkM",

"keyId" : "5066549580791808",

"name" : "to",

"emailAddress" : "to"

},

"message" : "msg21",

"sent" : "2008-09-08T22:47:31-07:00"

}

// Note : this is a different Message, but the behavior is the same.

Message :

@PersistenceCapable

public class Message {

@PrimaryKey

@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)

private Long id;

@Persistent(defaultFetchGroup = "true")

@OneToOne(fetch = FetchType.EAGER)

@Unowned

User from;

@Persistent(defaultFetchGroup = "true")

@OneToOne(fetch = FetchType.EAGER)

@Unowned

User to;

String message;

// getters and setters follow....

User:

@PersistenceCapable

public class User {

@PrimaryKey

@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)

@Extension(vendorName="datanucleus", key="gae.encoded-pk", value="true")

private String key;

@Persistent

@Extension(vendorName="datanucleus", key="gae.pk-id", value="true")

private Long keyId;

@Persistent(defaultFetchGroup = "true")

String name;

@Persistent(defaultFetchGroup = "true")

String emailAddress;

// Getters and setters follow...

相关阅读:
Top