0
漫畫對象可以有許多章節對象。Google App Engine中的有序列表 - JPA
我有這個在Comics
類:
@OneToMany(targetEntity=Chapter.class, mappedBy="comics", fetch=FetchType.LAZY, cascade={CascadeType.PERSIST, CascadeType.REMOVE})
private List<Chapter> chapters = null;
我在加入一章的漫畫方法:
public Chapter addChapter(Chapter chapter, String key) {
EntityManager em = EMF.get().createEntityManager();
EntityTransaction tx = null;
Comics comics = null;
try{
tx = em.getTransaction();
tx.begin();
comics = em.find(Comics.class, KeyFactory.stringToKey(key));
chapter.setPages(new LinkedList<Page>());
comics.getChapters().add(chapter);
tx.commit();
}catch(Exception ex){
ex.printStackTrace();
if(tx != null && tx.isActive())
tx.rollback();
} finally{
em.close();
}
return chapter;
}
我對閱讀漫畫方法:
public Comics read(String key) throws IllegalAccessException, InvocationTargetException{
EntityManager em = EMF.get().createEntityManager();
Comics comics = new Comics();
try{
Comics emComics = em.find(Comics.class, KeyFactory.stringToKey(key));
BeanUtils.copyProperties(comics, emComics);
comics.setChapters(new LinkedList<Chapter> (emComics.getChapters()));
}finally{
em.close();
}
return comics;
}
當我保存了新的Comics
,我也有:
comics.setChapters(new LinkedList<Chapter>());
問題是read
方法返回chapters
的意外排序。按順序顯示chapters
的最佳方法是什麼?
它的工作原理我的AppEngine? –
它的工作原理...謝謝.. –
你如何移動和刪除列表中的元素? 我成功移動了chapterNumber。但是,即使我爲剩餘的實體設置chapterNumber權限,刪除操作仍然無法正確檢索其餘實體。 – Srinivas