Hibernate生成表结构两种方式

来源:互联网 发布:zepto.js swipeleft 编辑:程序博客网 时间:2024/05/16 18:25
生成表结构两种方式: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);


1 0