JDO basics: List or array won't retrieve or return with GWT RPC

寵の児 提交于 2019-12-13 10:47:42

问题


I've been using Objectify up till now, but now I have to deal with some code using JDO. I'm having problems with basic stuff that is easy with Objectify, specifically: if an object has either a List or an array as a member, I can't get that to persist.

I have a class FileInfoBatch (code indents lost here, don't know why) containing a List of FileInfo:

@PersistenceCapable
public class FileInfoBatch implements Serializable{

private static final long serialVersionUID = 1L;        
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key key;

@Persistent
private List<FileInfo> fileInfoList;    

@Persistent    
private String savedByUserEmail;

public FileInfoBatch(){         
    fileInfoList=new ArrayList<FileInfo>();     
}

Then I send a FileInfoBatch (called fib) containing just 1 FileInfo in the List, to my RPC impl class & persist it, then query for it straight away for a test (in debugger)

    PersistenceManager pm = PMF.get().getPersistenceManager();
    pm.makePersistent(fib);
    Query query = pm.newQuery(FileInfoBatch.class, "savedByUserEmail == '"+ userEmail + "'");
    List<FileInfoBatch> savedList = (List<FileInfoBatch>) query.execute();
    FileInfoBatch persisted=savedList.get(0);

The persisted FileInfoBatch comes back with an empty FileInfo list. If I use a single Fileinfo member, this persists ok.

I find no such basic problem reported on this site & I've looked at the docs: https://developers.google.com/appengine/docs/java/datastore/jdo/dataclasses

Does such a simple storage task require huge complexity? If so I will go back to using Objectify.


回答1:


Define "doesn't persist"? Have you looked at the log (which tells you what is included in a PUT of an Entity) or the DB viewer for what is persisted? Is "FileInfo" marked as PersistenceCapable?

More than likely it is persisted, but you haven't paid attention to defining what is fetched (in JDO you get FULL control over what is in the retrieved object). Suggest that you read http://www.datanucleus.org/products/accessplatform_3_1/jdo/object_lifecycle.html and http://www.datanucleus.org/products/accessplatform_3_1/jdo/fetchgroup.html

Are you using a recent version of "datanucleus-appengine" ? (i.e v2.0 or later); the old versions aren't worth the effort.

PS, you don't need @Persistent on field types such as String, Key - makes things look much cleaner.

FWIW : JDO provides as simple a persistence choice as there is, as transparent as other options out there, and with semantics defined by a spec in way more detail than other options.



来源:https://stackoverflow.com/questions/13110506/jdo-basics-list-or-array-wont-retrieve-or-return-with-gwt-rpc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!