Spring启动,Hibernate - create-drop使用旧架构

时间:2018-03-17 11:34:45

标签: sql-server hibernate spring-boot orm

我有spring boot,spring数据,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

但是一旦我运行我的应用程序,我在stdout中看到了什么:

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

请注意,我已删除@Column registration date,将accountActivationUUID重命名为activationUUID,并将accountActive重命名为active

但是,我在stdout中看到了旧模式,它甚至存储在数据库中。

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

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

感谢您的回复:)

1 个答案:

答案 0 :(得分:0)

我发现了问题,并设法让它发挥作用。

问题出现在pom.xml中,有一些重复项和一些不存在的依赖项,因此运行只是落到最近成功运行。 这就是它如何使用旧架构。