【问题标题】:Spring boot, Hibernate - create-drop uses old schemaSpring boot,Hibernate - create-drop 使用旧模式
【发布时间】:2018-03-17 11:34:44
【问题描述】:

我有 spring boot、spring data、hibernate 和 ms sql, 但是使用create-drop 策略,hibernate 基于我的@Entity 类的旧实现创建表。

实体类如下:

@Entity
public class User {

    @Id
    @GeneratedValue
    private int id;

    @Column(unique = true, nullable = false)
    private String name;

    @Column(nullable = false)
    private String password;

    @Column(nullable = false)
    private String email;

    @Column(nullable = false)
    private boolean active = false;

    @Column
    private String activationUUID = UUID.randomUUID().toString();

    //getters and setters
}

在application.properties中,相关配置:

spring.jpa.hibernate.dialect=org.hibernate.dialect.SQLServer2012Dialect
spring.jpa.hibernate.ddl-auto=create-drop

但是我在标准输出中看到的,一旦我运行我的应用程序:

2018-03-17 12:08:10.973  INFO 876 --- [           main] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.SQLServer2008Dialect
2018-03-17 12:08:11.473  INFO 876 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000227: Running hbm2ddl schema export
Hibernate: drop table [user]
Hibernate: create table [user] ([id] int identity not null, [account_activationuuid] varchar(255), [account_active] bit not null, [email] varchar(255) not null, [name] varchar(255) not null, [password] varchar(255) not null, [registration_date] datetime2 not null, primary key ([id]))
Hibernate: alter table [user] add constraint UK_gj2fy3dcix7ph7k8684gka40c unique ([name])
2018-03-17 12:08:11.488  INFO 876 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000230: Schema export complete

注意我已经删除了@Columnregistration date,将accountActivationUUID重命名为activationUUID,并将accountActive重命名为active

不过,我在标准输出中看到了旧模式,它甚至像这样存储在数据库中。

那么,我的问题:
1) 这个旧模式从何而来?
2) hibernate 有一些模式缓存吗?
3) 如何让它每次都生成新的模式 - 在我的代码中准确表示 @Entity 类?
4) 为什么在stdout 中说使用2008 方言,即使我在application.properties 中指定了2012 方言?

我尝试使 intelj 中的缓存无效,重新启动计算机和数据库,以在硬盘驱动器上搜索具有旧架构定义的文件,但都没有成功。

感谢您的回复:)

【问题讨论】:

    标签: sql-server hibernate spring-boot orm


    【解决方案1】:

    我发现了问题并设法解决了问题。

    问题出在pom.xml,有一些重复项和一些不存在的依赖项,所以运行只是下降到最新的成功运行。 这就是它使用旧模式的方式。

    【讨论】:

      猜你喜欢
      • 2020-04-12
      • 1970-01-01
      • 2020-02-07
      • 2023-03-28
      • 2018-07-06
      • 2018-10-10
      • 2019-06-23
      • 2017-07-07
      • 2016-05-07
      相关资源
      最近更新 更多