Detach an entity from JPA/EJB3 persistence context

后端 未结 14 2131
面向向阳花
面向向阳花 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:11

    As far as I know, the only direct ways to do it are:

    1. Commit the txn - Probably not a reasonable option
    2. Clear the Persistence Context - EntityManager.clear() - This is brutal, but would clear it out
    3. Copy the object - Most of the time your JPA objects are serializable, so this should be easy (if not particularly efficient).

提交回复
热议问题