Hibernate生成表结构两种方式

xiaoxiao2021-02-27  164

生成表结构两种方式: 1,hbm2ddl.auto 自动生成表结构 <!-- create:先删除,再创建。 update:如果表不存在就创建,不一样就更新,一样就什么都不做。 create-dorp:初始化时创建表,SessionFactory执行close()时删除表。 validate:验证表结构是否一致,如果不一致,就抛异常。 --> <property name="hbm2ddl.auto">update</property> 2,使用SchemaExport工具类 //根据配置生成表结构 Configuration cfg = new Configuration().configure(); SchemaExport schemaExport = new SchemaExport(cfg); //第一个参数script的作用: print the DDL to the console(打印生成脚本到控制台) //第二个参数export的作用: export the script to the database(导出生成脚本到数据库) schemaExport.create(true, false);

转载请注明原文地址: https://www.6miu.com/read-12509.html

最新回复(0)