使用 dynamic-update 或 dynamic-insert 有积极的作用,但通常只对性能有轻微影响,http://www.mkyong.com/hibernate/hibernate-dynamic-update-attribute-example/ 也提到过。
但是引用文档提到这可能会对性能产生负面影响,如下文http://docs.jboss.org/hibernate/core/3.3/reference/en/html/mapping.html#mapping-declaration-class 中所述。 :
Although these settings can increase performance in some cases, they can actually decrease performance in others.
任何人都可以提出一些示例/场景来提及相同的负面性能影响吗?
最佳答案
Hibernate 为 每个 实体缓存实际的 INSERT/SELECT/UPDATE SQL 字符串,明显的好处是当您想要持久化、查找或更新实体时它不必计算 SQL .
但是,当使用动态插入或动态更新时,Hibernate 每次都必须生成相应的 SQL 字符串,因此在 Hibernate 方面存在性能成本。
换句话说,在数据库端和 Hibernate 端的开销之间进行权衡。
我的观点是动态插入和动态更新对于具有胖 blob 列的表或具有大量列的表可能很有趣。在其他情况下,我不相信动态插入或更新总是意味着性能提升(我默认不使用它们)。但与往常一样,您应该测量它。
另见
- Re: Request for dynamic update-SQL来自 Hibernate 开发者的一些反馈
关于java - hibernate : dynamic-update dynamic-insert - Performance Effects,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3404630/