【问题标题】:Hibernate not automatically creating tables [duplicate]Hibernate不会自动创建表[重复]
【发布时间】:2018-08-18 01:23:45
【问题描述】:

我在我的 spring 项目中设置了 hibernate,一旦在我的数据库中创建了表,它就可以正常工作,但是我希望我的 hibernate 自动为我创建表。我没有使用 xml 进行配置,我使用的是 application.properties 文件和 hibernateConfig.java 类。

application.properties

hibernate.format_sql = true
hibernate.dialect=org.hibernate.dialect.HSQLDialect
hibernate.show_sql=true
hibernate.hbm2ddl.auto=update

HibernateConfig.java

  private Properties hibernateProperties() {
    Properties properties = new Properties();
    properties.put("hibernate.dialect", environment.getRequiredProperty("hibernate.dialect"));
    properties.put("hibernate.show_sql", environment.getRequiredProperty("hibernate.show_sql"));
    properties.put("hibernate.format_sql", environment.getRequiredProperty("hibernate.format_sql"));
    properties.put("hibernate.hbm2ddl.auto", environment.getRequiredProperty("hibernate.hbm2ddl.auto"));


    return properties;        
}

任何建议将不胜感激!

【问题讨论】:

    标签: java spring hibernate nhibernate-configuration


    【解决方案1】:

    将属性改为hibernate.hbm2ddl.auto=create

    【讨论】:

      【解决方案2】:

      看看https://docs.spring.io/spring-boot/docs/current/reference/html/howto-database-initialization.html 并设置属性 hibernate.dbm2ddl.auto=create。

      这应该可以解决问题。

      【讨论】:

      • 我已经把它改成了这个,但它现在给我一个错误,说它无法提取结果集并且它仍然没有创建表......有什么建议吗?
      • 那将是一个完全不同的问题,你应该在一个单独的问题中发布,因为这个问题显然已经解决了。此外,我们需要更多代码来判断这类问题(即您尝试自动创建的模型等)
      猜你喜欢
      • 2018-11-19
      • 2017-08-23
      • 2012-07-02
      • 2021-09-15
      • 1970-01-01
      • 2011-04-05
      • 2020-11-16
      • 2013-12-04
      • 2016-05-26
      相关资源
      最近更新 更多