Why need detached entities in JPA?

前端 未结 6 597
礼貌的吻别
礼貌的吻别 2021-01-31 09:28

There are always so many questions related to issues with detached entities!

First, they often cause LazyInitializationException in Hibernate. Yes, there ar

6条回答
  •  北荒
    北荒 (楼主)
    2021-01-31 09:42

    Detached entities exists only to minimize the time your data is locked due to a transaction, maximizing the number of simultaneous users. Of course, this comes with a cost, and you listed them. but since merging conflicts are usually rare, people accept some rare bugs.

    You see, data conflics will always exist, but they occur less when the transaction is short :-)

提交回复
热议问题