dynamic-insert dynamic-update mutable="false" (让hibernate生成的sql不包括所有字段、指定不可变的实体)...

本文探讨了在使用Hibernate处理具有大量列的遗留表时,如何通过配置动态插入和更新属性来优化SQL生成过程,减少启动时间和提高性能。通过设置实体类的mutable属性为false,可以避免不必要的SQL打印和错误,实现更高效的数据操作。
Hibernate生成update语句,会更新所有的列。
在有些情况下,例如包含几百列的一个遗留表,在该表中,即使最简单的操作的sql语句也很大,必须关闭这个启动时
的sql生成,并切换到运行时生成的动态语句。当大量实体时,也会影响启动时间,因为hibernate必须为CURD提前生
成所有SQL语句:
区别就是:
Hibernate: insert into USER (user_Name) values (?)
Hibernate: insert into USER (user_Name, password) values (?, ?)
配置:
  1. <classname="User"table="USER"dynamic-insert="true"dynamic-update="true">

  1. @org.hibernate.annotations.Entity(dynamicInsert=true,dynamicUpdate=true)


使实体不可变:
一个特定类的实例可以是不可变的。
效果:
没有sql打印,也没有报错,也就是忽略了更新操作

配置:
  1. <classname="User"table="USER"dynamic-insert="true"dynamic-update="true"
  2. mutable="false">

  1. @org.hibernate.annotations.Entity(dynamicInsert=true,dynamicUpdate=true,mutable=false)


  1. @org.hibernate.annotations.AccessType
  2. The annotation@org.hibernate.annotations.AccessType should be considered deprecatedforFIELD and PROPERTY access. It is still useful howeverifyou need to use a custom access type.
[-agentlib:jdwp=transport=dt_socket,address=127.0.0.1:56882,suspend=y,server=n, -Drebel.base=C:\Users\Administrator\.jrebel, -Drebel.env.ide.plugin.build=2d7357bde6d770c5760a889e2d4bf4d26276ce12, -Drebel.env.ide.plugin.version=2025.2.0, -Drebel.env.ide.version=2024.3.1.1, -Drebel.env.ide.product=IU, -Drebel.env.ide=intellij, -Drebel.notification.url=http://localhost:54734, -Xshare:off, -agentpath:C:\Users\Administrator\AppData\Roaming\JetBrains\IntelliJIdea2024.3\plugins\jr-ide-idea\jrebel6\lib\jrebel64.dll, -agentpath:C:\Users\Administrator\AppData\Local\Temp\idea_libasyncProfiler_dll_temp_folder6\libasyncProfiler.dll=version,jfr,event=wall,interval=10ms,cstack=no,file=C:\Users\Administrator\IdeaSnapshots\Application_2025_11_04_141856.jfr,dbghelppath=C:\Users\Administrator\AppData\Local\Temp\idea_dbghelp_dll_temp_folder7\dbghelp.dll,log=C:\Users\Administrator\AppData\Local\Temp\Application_2025_11_04_141856.jfr.log.txt,logLevel=DEBUG, -XX:TieredStopAtLevel=1, -Dspring.output.ansi.enabled=always, -Dcom.sun.management.jmxremote, -Dspring.jmx.enabled=true, -Dspring.liveBeansView.mbeanDomain, -Dspring.application.admin.enabled=true, -Dmanagement.endpoints.jmx.exposure.include=*, -javaagent:C:\Users\Administrator\AppData\Local\JetBrains\IntelliJIdea2024.3\captureAgent\debugger-agent.jar, -Dkotlinx.coroutines.debug.enable.creation.stack.trace=false, -Ddebugger.agent.enable.coroutines=true, -Dkotlinx.coroutines.debug.enable.flows.stack.trace=true, -Dkotlinx.coroutines.debug.enable.mutable.state.flows.stack.trace=true, -Dfile.encoding=UTF-8, -Dsun.stdout.encoding=UTF-8, -Dsun.stderr.encoding=UTF-8]
最新发布
11-05
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值