Entity must be managed to call remove

前端 未结 2 564
离开以前
离开以前 2021-02-13 06:55

What\'s going on here?

@Stateless
@LocalBean
public class AppointmentCommentDao {
    public void delete(long appointmen         


        
相关标签:
2条回答
  • 2021-02-13 07:27

    In your case merge is not needed, because ac is not deattached in any point between em.find and em.remove.

    In general when entity is deattached, EntityManager's method merge takes entity as argument and returns managed instance. Entity given as argument does not transform to be attached. This is explained for example here: EntityManager.merge. You have to go for:

        AppointmentComment toBeRemoved = em.merge(ac);
        em.remove(toBeRemoved);
    
    0 讨论(0)
  • 2021-02-13 07:31

    Try this:

    entity = getEntityManager().getReference(AppointmentComment.class, entity.getId());
    getEntityManager().remove(entity);
    
    0 讨论(0)
提交回复
热议问题