我有两个类 Post, Comment 大致的代码是这样的:@PersistenceCapable
public class Post implements Serializable {
private static final long serialVersionUID = -1920489288184318045L; @PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key key;
@Persistent
private List<Comment> comments;}@PersistenceCapable
public class Comment implements Serializable {
private static final long serialVersionUID = 5201324337930430040L; @PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Key key;
@Persistent
private String name;
}
以下是一个DAO的代码是对一个已经存在的Post 添加一个新的comment, 但是就是存不进去,commet list一直是空的 public boolean addComment(Long postId, Comment comment) {
PersistenceManager pm = JdoConnectionPool.getInstance().getPersistenceManager("jdo-default");
Key k = KeyFactory.createKey(Post.class.getSimpleName(), postId);
Post persistedPost = null;
try {
persistedPost = pm.getObjectById(Post.class, k);
persistedPost.addComment(comment);
            return true;
} finally {
pm.close();
}

}
我查了好久也看到很多人有这样问题就是没有找到解决方法,不知道各位大虾碰到过这样的问题马?