HiLo generator strategy not working

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

    The Support for 'hilo' generator has been removed. For additional information, this link gives you the deprecated list.

    To overcome this, you can simply use sequence generator. This will solve your problem.

    @Entity
    @Table(name = "USER_DETAILS")
    public class UserDetails {
    
        @Id
        @GeneratedValue(strategy = GenerationType.IDENTITY)
        private int userId;
        private String userName;
    
        @ElementCollection
        @JoinTable(name="USER_ADDRESS",
            joinColumns=@JoinColumn(name="USER_ID")
        )
    
        @GenericGenerator(name = "sequence-gen", strategy = "sequence")
        @CollectionId(columns = { @Column(name="ADDRESS_ID") }, generator = "sequence-gen", type = @Type(type="long"))
        private Collection
    address = new ArrayList
    (); public int getUserId() { return userId; } public void setUserId(int userId) { this.userId = userId; } public String getUserName() { return userName; } public void setUserName(String userName) { this.userName = userName; } public Collection
    getAddress() { return address; } public void setAddress(List
    address) { this.address = address; } }

提交回复
热议问题