JPA脏检查 [英] JPA dirty checking
问题描述
我的问题是,JPA如何跟踪变化?实体不被拦截(通过代理),所以肯定不会拦截setter,它是如何做的?
我对这个脏检查功能的实现细节感兴趣。
他们执行完全依赖于实现的功能(即JPA规范在这里不会帮助您)。
某些实现(例如DataNucleus,OpenJPA)使用字节码增强功能,并能够有效地管理加载后哪些字段变脏(并且不需要保留原始的快照字段值)。
其他实现必须与早期的某些值进行比较(或通过与数据存储区进行比较)。
I know that JPA implementors (like Hibernate) monitor the entities attached to the persistence context, and if any field of any entity is changed, then the change is updated to the database.
My question is, how does JPA keep track of the changes? The Entities are not intercepted (by proxyies), so for sure it is not throught the interception of the "setters", how is it done?
I am interested on the implementation detail of this "dirty checking" feature.
They do something that is totally implementation dependent (i.e JPA spec doesn't help you one bit here).
Some implementations (e.g DataNucleus, OpenJPA) use bytecode enhancement and are able to efficiently manage what fields are dirty since loading (and have no need of keeping a snapshot of the original field values).
Other implementations have to compare with some value from earlier (or via a comparison with the datastore).
这篇关于JPA脏检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!