entityManager.getTransaction().rollback() detaches entities?

后端 未结 2 756
借酒劲吻你
借酒劲吻你 2021-01-21 06:38

I have the following piece of code:

EntityManagerFactory emf = Persistence.createEntityManagerFactory(\"test\")
EntityManager entityManager = emf.createEntityMan         


        
相关标签:
2条回答
  • 2021-01-21 07:16

    In a PersistenceContext of "Transaction" then commit/rollback will detach objects used in the transaction. In PersistenceContext of "Extended" then commit/rollback do nothing like that, and objects are detached at close of the EM. Depends on your context

    0 讨论(0)
  • 2021-01-21 07:38

    From the JSR-000317 Persistence Specification for Eval 2.0 Eval:

    3.3.2 Transaction Rollback

    For both transaction-scoped and extended persistence contexts, transaction rollback causes all pre-existing managed instances and removed instances [31] to become detached. The instances’ state will be the state of the instances at the point at which the transaction was rolled back. Transaction rollback typically causes the persistence context to be in an inconsistent state at the point of rollback. In particular, the state of version attributes and generated state (e.g., generated primary keys) may be inconsistent. Instances that were formerly managed by the persistence context (including new instances that were made persistent in that transaction) may therefore not be reusable in the same manner as other detached objects—for example, they may fail when passed to the merge operation. [32]

    0 讨论(0)
提交回复
热议问题