Has Spring-boot changed the way auto-increment of ids works through @GeneratedValue?

后端 未结 4 1782
难免孤独
难免孤独 2021-02-12 20:25

Spring-Boot 2.0.0 seems to have modified the way Hibernate is auto configured.

Let\'s suppose two simple and independent JPA entities:

4条回答
  •  名媛妹妹
    2021-02-12 20:58

    As Andrew has pointed out in the comment, if you don't want the id to be incremented while values are created in other tables, you can specify your ID like this:

    @Id
    @GeneratedValue(
        strategy= GenerationType.AUTO,
        generator="native"
    )
    @GenericGenerator(
        name = "native",
        strategy = "native"
    )
    private Long id;
    

    Doing this will make each table has its unique id beginning with 1,2,3 ... and so on.

提交回复
热议问题