当我使用A JPA Query的getResultList()时,结果是分离还是管理? [英] When I use A JPA Query's getResultList(), are the results detached or managed?
问题描述
当我有一个我调用.getResultList()的JPA查询时,它会返回一个对象列表。是否管理或分离了该列表中的对象?也就是说,如果我对它们进行更改,或者这些更改是否会自动获取,我是否需要担心合并或持久化?
When I have a JPA Query that I call .getResultList(), It gives me back a List of objects. Are the objects in that list managed or detached? That is, do I have to worry about merging or persisting them later if I make changes to them, or will those changes be picked up automatically?
推荐答案
是的,管理从 .getResultList()
返回的对象。
Yes, the objects returned from .getResultList()
are managed.
当您对托管对象进行更改时,您不必担心合并,因为这些更改将由 EntityManager $ c获取$ c>自动。
When you made changes on the managed objects, you do not worry about merging as those changes will be picked up by the EntityManager
automatically.
当用于加载该对象的 EntityManager
close(), clear()或分离()。分离的对象不再被管理,你应该合并让 EntityManager
获取更改。
The managed objects will become detached when the EntityManager
that is used to load that object is close(), clear() or detach(). Detached objects are not manged anymore and you should do merging to let the EntityManager
pick up the changes.
这篇关于当我使用A JPA Query的getResultList()时,结果是分离还是管理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!