我试图运行这个基本的JPA/EJB代码:“分离的实体传递给坚持错误” 使用JPA/EJB代码
public static void main(String[] args){
UserBean user = new UserBean();
user.setId(1);
user.setUserName("name1");
user.setPassword("passwd1");
em.persist(user);
}
我得到这个错误:
javax.ejb.EJBException: javax.persistence.PersistenceException: org.hibernate.PersistentObjectException: detached entity passed to persist: com.JPA.Database
任何想法?
我在互联网上搜索,我发现原因是:
This was caused by how you created the objects, i.e. If you set the ID property explicitly. Removing ID assignment fixed it.
但我没有得到它,我将不得不修改获取代码的工作?
如果你使用泛型,没有必要使用“targetEntity = Photo.class” – Rollerball 2016-03-01 17:36:56
嗨,将相册对象设置为photo1后nad photo2 ...我们必须保存哪些对象照片或相册列表? – 2017-01-23 06:06:20