我真的想知道更多关于更新,导出和值,可以给hibernate.hbm2ddl.auto 我需要知道什么时候使用更新,什么时候不?另一种选择是什么?
以下是在DB中可能发生的变化:
新表 旧表中的新列 列删除 事件解释列的数据类型发生变化 列的类型更改了其属性 表了 事件解释列值发生变化
在每种情况下,最佳解决方案是什么?
我真的想知道更多关于更新,导出和值,可以给hibernate.hbm2ddl.auto 我需要知道什么时候使用更新,什么时候不?另一种选择是什么?
以下是在DB中可能发生的变化:
新表 旧表中的新列 列删除 事件解释列的数据类型发生变化 列的类型更改了其属性 表了 事件解释列值发生变化
在每种情况下,最佳解决方案是什么?
当前回答
我觉得你应该集中精力
SchemaExport Class
这个类使你的配置动态 所以它可以让你选择你最喜欢的套间…
结帐 [架构导出]
其他回答
我会使用liquibase来更新您的数据库。Hibernate的模式更新特性实际上只适用于开发新特性的开发人员。在生产环境中,需要更谨慎地处理db升级。
我觉得你应该集中精力
SchemaExport Class
这个类使你的配置动态 所以它可以让你选择你最喜欢的套间…
结帐 [架构导出]
给任何人搜索默认值…
它是在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;
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”列,表必须是空的。
综上所述…… 注意,这个属性叫做dll。auto和应该只控制dll操作(创建/删除模式/表),我惊讶地发现它也与dml有关:只有更新将允许插入数据,这是dml操作。
在试图将数据填充到内存数据库时被此捕获;只有更新有效。