java.lang.IllegalArgumentException: Removing a detached instance com.test.User#5

前端 未结 5 1736
执笔经年
执笔经年 2020-12-07 16:32

I have a java EE project using JPA (transaction-type=\"JTA\"), hibernate as provider. I write my beans to handle the CRUD things. The program running in JBOSS 7 AS.

5条回答
  •  情歌与酒
    2020-12-07 17:04

    I faced the same problem. The detached entity should be re-attached. As @BalusC mentioned, using EntityManager.merge() should be used to attach the detached entity. EntityManager.merge() generates SQL Query which fetches the current state of the entity, on which EntityManager.remove() has to be performed. But in my case it didn't worked. Try EntityManager.remove(EntityManager.find(Class,arg)) instead. It worked for me.

提交回复
热议问题