【问题标题】:Spring boot packing from jar to war hibernate sequence has been reset从 jar 到战争休眠序列的 Spring Boot 打包已重置
【发布时间】:2016-12-30 05:22:40
【问题描述】:

我使用的是上个月的 Spring boot 1.4.2 版本,我的应用程序作为 jar 文件运行,现在我已将其打包为 war 文件。但我面临一个问题,即

@Id
@GeneratedValue(strategy = GenerationType.AUTO)

已重新开始,但表有 40 多条记录。谁能帮我解决这个问题?

【问题讨论】:

    标签: spring hibernate maven spring-mvc spring-boot


    【解决方案1】:

    您可以稍微更改您的代码以使用SequenceGenerator。有了它,您可以定义一个initialValue,它可以大于表中已有的记录。

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator="seq")
    @SequenceGenerator(name="seq", initialValue=50, allocationSize=1)
    

    【讨论】:

      【解决方案2】:

      这个问题是由于hibernate 5造成的。在spring boot 1.4.2中,hibernate版本已更改为5版本。您可以使用此属性使用相同的休眠序列

      "hibernate.id.new_generator_mappings", "false"
      

      【讨论】:

        猜你喜欢
        • 2020-02-26
        • 2018-03-12
        • 1970-01-01
        • 2018-12-16
        • 2019-01-10
        • 2019-03-23
        • 1970-01-01
        • 2018-07-05
        • 2022-11-10
        相关资源
        最近更新 更多