为什么Hibernate默认设置动态插入= false [英] Why does Hibernate set dynamic insert=false by default

查看:86
本文介绍了为什么Hibernate默认设置动态插入= false的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以向我解释为什么Hibernate默认设置了 Dynamic insert = false ,这是什么原因?

解决方案

What @ jb-nizet says。

另外, dynamic-insert =true在我的书中是一个坏主意。



从生成的SQL中跳过空字段,很快你会发现自己处于一种情况,你将声明列 not null default 这实际上导致持久性数据与休眠知道的实体数据不同。这会导致沮丧,并可能使你诉诸昂贵的 session.refresh()调用。

例如,假设列

  MESSAGE varchar(64)not null default''

,并且为映射到此列的属性保存一个空值实体。



使用动态插入你最终会得到一个实体,它的内存属性消息的值为空,同时相应的数据库行有''。感。特别是如果你正在考虑动态插入这种情况(为了避免为非空列设置所有属性并依赖默认约束),再考虑一下。


Could anyone explain to me why Hibernate sets the Dynamic insert=false by default, and what's the reason for that?

解决方案

What @jb-nizet said.

Also, dynamic-insert="true" is a bad idea in my book.

Skipping null fields from the generated SQL, soon you will find yourself in a situation where you will be declaring columns not null default which in fact causes the persistent data to be different than the entity data that hibernate knows about. This will cause frustration and likely make you resort to expensive session.refresh() calls.

For example suppose column

MESSAGE varchar(64) not null default ''

and you save an entity with null value for the property that is mapped to this column.

With dynamic-insert you will end up with an entity that has null value for the property message in-memory while at the same time the corresponding database row has ''.

I hope I made sense. Especially if you are considering dynamic-insert for such a scenario (to get away from having to set all properties for not null columns and rely on a default constraint), think again.

这篇关于为什么Hibernate默认设置动态插入= false的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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