chi*_*tiz 13 java select hibernate sql-update
我开始在我的APP中使用这2个休眠注释.
@DynamicUpdate(value=true)
@SelectBeforeUpdate(value=true)
Run Code Online (Sandbox Code Playgroud)
首先,我将尝试解释我对它的理解,以了解我是否正确.
@DynamicUpdate(value=true)
Run Code Online (Sandbox Code Playgroud)
仅更新modified values实体中的内容Hibernate needs to track those changes
@SelectBeforeUpdate(value=true)
Run Code Online (Sandbox Code Playgroud)
创建一个select之前update知道哪些属性已被更改,这在实体已在不同会话上加载和更新时很有用Hibernate is out of tracking entity changes
这2个肯定是否正确?
我主要担心的是.
在DB performance哪个更好或更快地更新所有的实体领域的一次或generate a select to know which columns update and update only the modified columns?
情况取决于您的情况.如果你的表非常简单(没有外键约束,只有几列,几个索引),那么更新完整记录会更快.
但是,如果您的表具有许多外键约束和索引,则首先选择然后更新差异会更快.这是因为PostgreSQL必须为更新中的每一列执行以下工作:
此外,这些变化增加了表格的膨胀,必须通过真空清理.
请记住,如果在包含许多表的数据库上使用dynamicUpdate,并且您的更新看起来非常不同,那么您将开始逐出缓存的查询计划.这些计划耗费资源来计算新鲜度.但是,缓存计划可能只对同一会话中的后续查询有用.