休眠动态更新 [英] Hibernate dynamic-update

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

问题描述

我从 here 知道,hibernate可以配置为UPDATE到数据库只有一个已被修改的实体的字段,而不是实体的所有字段(即使它们没有被更改)。这是默认的行为。



我的问题是,为什么以后的默认行为,不应该是UPDATE只是修改的字段的默认行为? p>

此外,为什么甚至支持未修改字段的更新?是否有理由更新未修改的字段?

解决方案


我的问题是,为什么晚默认行为,不应该是
是UPDATE的默认行为只是修改的字段?


只更新修改的字段如果有大量的属性被大部分的业务逻辑应用程序修改都是昂贵的。因为它包括脏检查(这是另一个选择查询来标识修改的字段)。当有20个字段并且仅修改少量字段时,这种动态更新是很好的(因为可以在DML语句中添加少量列来执行,以获得性能)。如果超过50%的字段被修改,那么更新所有属性是很好的。所以,选择给开发者决定更新只有修改的字段。



希望我的输入将帮助您理解这一点。如果我错了,专家请纠正我。


I know from here that hibernate is configurable to UPDATE to database only the fields of an entity that have been modified, instead of all the fields of the entity (even if they are not changed). This is the default behaviours.

My question is, why is the later the default behaviour, shouldn't it be the default behaviour to UPDATE just the modified fields?

And further, why is it even supported the UPDATE of unmodified fields? is there a reason to UPDATE unmodified fields?

解决方案

My question is, why is the later the default behaviour, shouldn't it be the default behaviour to UPDATE just the modified fields?

As updating only modified fields is a costly if there are huge number of properties are get modified by application in most of it's business logic. As it includes dirty checking(which is another select query to identify the modified fields). This dynamic-update is good when there were 20 fields and only few fields are modified(as few columns can be added in DML statement for execution which gains performance). If more than 50% fields are modified then it's good to update all the properties. So, choice is given to developer to decide as to update only modified fields.

Hope my input will help you understanding this. Experts please correct me if I am wrong.

这篇关于休眠动态更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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