【问题标题】:Which dependency is responsible for creation of tables from spring boot entities automatically哪个依赖负责自动从 Spring Boot 实体创建表
【发布时间】:2021-10-31 19:23:27
【问题描述】:

我有一个 spring-boot 项目,但我希望它在我指定 @Table@Entity 时将 实体类 迁移到数据库表注释。目前,我正在手动创建表。

下面是我的HibernateJpaVendorAdapter

        HibernateJpaVendorAdapter vendorAdapter
                = new HibernateJpaVendorAdapter();
        em.setJpaVendorAdapter(vendorAdapter);
        HashMap<String, Object> properties = new HashMap<>();
        properties.put("spring.jpa.generate-ddl",env.getProperty("spring.jpa.generate-ddl"));
        properties.put("spring.jpa.hibernate.ddl-auto",
                env.getProperty("spring.jpa.hibernate.ddl-auto"));
        em.setJpaPropertyMap(properties);

        return em;

下面是application.properties

【问题讨论】:

  • 请在您的问题中包含您的应用程序属性的实际文本。我可以阅读该图像中的内容。

标签: java spring-boot spring-data-jpa


【解决方案1】:

您的类路径中需要spring-boot-starter-data-jpa 依赖项,并且您必须在application.properties 中将spring.jpa.hibernate.ddl-auto 设置为updatecreate

但它不应该用于生产。

【讨论】:

  • 如何使用上面的适配器来做到这一点?
  • 你系统中hibernate.hbm2ddl.auto的值是多少?尝试将此值设置为updatecreatespring.jpa.hibernate.ddl-auto 应该是 hibernate.hbm2ddl.auto 的包装器。
  • 我已经按照您上面的建议进行了更新,但它没有创建新表
  • 您的属性中有spring.jpa.generate-ddl=true 吗?请尝试添加它们。
  • 我做了 spring.jpa.generate-ddl=true 但仍然没有创建或更新表格。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-24
  • 1970-01-01
  • 2015-01-06
  • 1970-01-01
  • 2021-08-13
相关资源
最近更新 更多