HiLo generator strategy not working

后端 未结 7 600
伪装坚强ぢ
伪装坚强ぢ 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:47

    This is what works for apps on PostgreSQL. Though I have not tested it, it should work for all DBs. Note that increment-gen is used not sequence.

    @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
    listOfAddresses = new ArrayList
    ();

提交回复
热议问题