我有一个对象 PictureBook ,其中包含一个带有持久性注释的 List< Picture> 。
@PersistenceCapable(identityType = IdentityType.APPLICATION,
detachable = "true")
public class PictureBook {
/**
* primary key - type encoded String
*/
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
@Extension(vendorName = "datanucleus", key = "gae.encoded-pk", value = "true")
private String key;
@Persistent
private String name;
@Persistent
private String creator;
@Persistent
private String link;
@Persistent
private String cover;
@Persistent(mappedBy = "pictureBook")
private List<Picture> pictures;
图片类有对pictureBook类的引用
@PersistenceCapable(identityType = IdentityType.APPLICATION,
detachable = "true")
public class Picture implements Serializable {
/**
* primary key - type encoded String
*/
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
@Extension(vendorName = "datanucleus", key = "gae.encoded-pk", value = "true")
private String key;
@Persistent
private String albumName;
@Persistent
private String creator;
@Persistent
private String link;
@Persistent
private PictureBook pictureBook;
public Picture() {
}
public Picture(String albumName, String creator, String link) {
this.albumName = albumName;
this.creator = creator;
this.link = link;
}
在本地测试时,一切都按预期进行,但是当我部署到 appengine 时,我得到一个异常,告诉“xxx 类型的对象和身份 yyy 没有正确分离”。当我查询我的所有 PictureBook 实体时,我得到了这个。任何人都可以帮助我我真的坚持这个:/查询的方法如下:
public List<PictureBook> getAllPictureBooks() {
log.info("retrieving all PictureBooks from datastore...");
PersistenceManager persistenceManager = PMF.getInstance().getPersistenceManager();
Query retrieveAllPictureBooks = persistenceManager.newQuery(PictureBook.class);
List<PictureBook> albumList = null;
List<PictureBook> albums = null;
try {
albumList = (List<PictureBook>) retrieveAllPictureBooks.execute();
for(PictureBook pictureBook: albumList){
System.out.println(pictureBook.getPictures().size());
}
albums = (List<PictureBook>)persistenceManager.detachCopyAll(albumList);
} catch (Exception e) {
log.error("an exception occured: \n" + e.getMessage());
} finally {
if (persistenceManager != null) {
persistenceManager.close();
log.info("persistenceManager closed");
}
}
return albums;
}