HiLo generator strategy not working

后端 未结 7 503
伪装坚强ぢ
伪装坚强ぢ 2021-02-04 09:02

I am new to hibernate. What I am trying to do is use @CollectionIdto generate an identifier for my Address class. I have used Collection interface for

7条回答
  •  终归单人心
    2021-02-04 09:45

    If we are using mysql it would be better to use the @GenericGenerator of increment strategy.

    1. sequence - This sort of strategy supports by Oracle, Postgresql.
    2. increment - This sort of strategy supports by MySql.

      @ElementCollection
      @JoinTable(name="USER_ADDRESS", joinColumns=@JoinColumn(name="USER_ID"))
      @GenericGenerator(name = "increment-gen", strategy = "increment")
      @CollectionId(columns = { @Column(name="ADDRESS_ID") }, generator = "increment-gen", type = @Type(type="long"))
      private Collection
      listOfAddress = new ArrayList<>();

    When I have used the sequence strategy with MySql I came across an issue where my ADDRESS_ID is not getting incremented properly.

提交回复
热议问题