JPA脏检查 [英] JPA dirty checking

查看:135
本文介绍了JPA脏检查的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道JPA实现者(如Hibernate)监视连接到持久性上下文的实体,如果任何实体的任何字段被更改,则更改将更新到数据库。



我的问题是,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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆