在我的个人资料类中,我有
@OneToOne(cascade=CascadeType.PERSIST)
private ProfilePicture profilePic = null;
我更新个人资料的方法图片
public Profile updateUserProfilePic(Profile user) {
EntityManager em = EMF.get().createEntityManager();
em.getTransaction().begin();
Profile userx = em.find(Profile.class, user.getEmailAddress());
userx.setProfilePic( user.getProfilePic() );
em.getTransaction().commit();
em.close();
return userx;
}
当调用updateUserProfilePic时,它只是在数据存储中添加另一个profilePic,它不会替换现有的profilePic。我的实现是否正确?我想更新个人资料图片。
">
瞬态"表示不持久和不分离。
使用该版本的 GAE JPA,如果您希望分离对象或托管对象重用现有对象,则需要该对象。
使用 Google 插件的 v2,有一个持久性属性,允许合并设置了"id"字段的瞬态对象。