在构建hibernate 4.1.2期间生成模式文件

时间:2012-05-03 04:16:17

标签: hibernate maven

我目前正在使用Hibernate 3.6.9和hibernate3-maven-plugin。我使用目标hbm2ddl生成一个sql架构文件。

该插件不支持Hibernate 4.1.2。如何生成模式文件?

1 个答案:

答案 0 :(得分:2)

hibernate3-maven-plugin只需调用SchemaExport即可生成架构文件。为什么不自己手动调用呢?

示例:

Configuration config = new Configuration();

Properties properties = new Properties();

properties.put("hibernate.dialect", "org.hibernate.dialect.PostgreSQLDialect");
properties.put("hibernate.connection.url", "jdbc:postgresql://localhost:5432/Test"); 
properties.put("hibernate.connection.username", "username");
properties.put("hibernate.connection.password", "password");
properties.put("hibernate.connection.driver_class", "org.postgresql.Driver");
properties.put("hibernate.show_sql", "true");
config.setProperties(properties);

config.addAnnotatedClass(MyMappedPojo1.class);
config.addAnnotatedClass(MyMappedPojo2.class);
..................

SchemaExport schemaExport = new SchemaExport(config);

/**Just dump the schema SQLs to the console , but not execute them ***/
schemaExport.create(true, false);