Detach an entity from JPA/EJB3 persistence context

后端 未结 14 2136
面向向阳花
面向向阳花 2020-12-13 03:26

What would be the easiest way to detach a specific JPA Entity Bean that was acquired through an EntityManager. Alternatively, could I have a query return detached objects in

14条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-13 04:19

    If there aren't too many properties in the bean, you might just create a new instance and set all of its properties manually from the persisted bean.

    This could be implemented as a copy constructor, for example:

    public Thing(Thing oldBean) {
      this.setPropertyOne(oldBean.getPropertyOne());
      // and so on
    }
    

    Then:

    Thing newBean = new Thing(oldBean);
    

提交回复
热议问题