【问题标题】:generate schema file during build for hibernate 4.1.2在构建期间为 hibernate 4.1.2 生成模式文件
【发布时间】:2012-05-12 14:15:17
【问题描述】:

我目前正在使用带有 hibernate3-maven-plugin 的 Hibernate 3.6.9。我使用目标 hbm2ddl 生成一个 sql 模式文件。

该插件不支持 Hibernate 4.1.2。如何生成架构文件?

【问题讨论】:

    标签: hibernate maven


    【解决方案1】:

    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);
    

    【讨论】:

      猜你喜欢
      • 2018-09-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-21
      相关资源
      最近更新 更多