我真的想知道更多关于更新,导出和值,可以给hibernate.hbm2ddl.auto 我需要知道什么时候使用更新,什么时候不?另一种选择是什么?
以下是在DB中可能发生的变化:
新表 旧表中的新列 列删除 事件解释列的数据类型发生变化 列的类型更改了其属性 表了 事件解释列值发生变化
在每种情况下,最佳解决方案是什么?
我真的想知道更多关于更新,导出和值,可以给hibernate.hbm2ddl.auto 我需要知道什么时候使用更新,什么时候不?另一种选择是什么?
以下是在DB中可能发生的变化:
新表 旧表中的新列 列删除 事件解释列的数据类型发生变化 列的类型更改了其属性 表了 事件解释列值发生变化
在每种情况下,最佳解决方案是什么?
当前回答
我觉得你应该集中精力
SchemaExport Class
这个类使你的配置动态 所以它可以让你选择你最喜欢的套间…
结帐 [架构导出]
其他回答
我觉得你应该集中精力
SchemaExport Class
这个类使你的配置动态 所以它可以让你选择你最喜欢的套间…
结帐 [架构导出]
validate: It validates the schema and makes no changes to the DB. Assume you have added a new column in the mapping file and perform the insert operation, it will throw an Exception "missing the XYZ column" because the existing schema is different than the object you are going to insert. If you alter the table by adding that new column manually then perform the Insert operation then it will definitely insert all columns along with the new column to the Table. Means it doesn't make any changes/alters the existing schema/table.
更新:在执行操作时,会改变数据库中已有的表。 您可以使用hbm2ddl的这个选项添加或删除列。 但是如果你要添加一个'NOT NULL'的新列,那么它将忽略向DB添加特定的列。因为如果你想在现有的表中添加“NOT NULL”列,表必须是空的。
给任何人搜索默认值…
它是在spring-boot 2.0.5版本和JpaProperties 1.1.0版本的源代码中编写的:
/**
* DDL mode. This is actually a shortcut for the "hibernate.hbm2ddl.auto"
* property. Defaults to "create-drop" when using an embedded database and no
* schema manager was detected. Otherwise, defaults to "none".
*/
private String ddlAuto;
hibernate.hbm2ddl。auto在创建sessionFactory时自动验证DDL并将其导出到模式。
默认情况下,不会自动对DB进行任何创建或修改。如果用户设置了以下值之一,那么它将自动进行DDL模式更改。
创建—正在创建模式 <输入键= " hibernate.hbm2ddl。汽车“价值= "创建" > 更新——更新现有的模式 <输入键= " hibernate.hbm2ddl。汽车“价值= "更新" > 验证—验证现有的模式 <输入键= " hibernate.hbm2ddl。汽车“价值= "验证" > 创建-删除—在会话开始和结束时自动创建和删除模式 <输入键= " hibernate.hbm2ddl。汽车“价值= " create-drop " >
Validate:验证模式,不对数据库进行任何更改。 更新:使用当前执行查询更新架构。 Create:每次创建新的模式,并销毁之前的数据。 create-drop:当应用程序停止或显式关闭SessionFactory时删除模式。