HiLo generator strategy not working

后端 未结 7 487
伪装坚强ぢ
伪装坚强ぢ 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> address = new ArrayList<Address>();
    
        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<Address> getAddress() {
            return address;
        }
    
        public void setAddress(List<Address> address) {
            this.address = address;
        }
    }
    
    0 讨论(0)
提交回复
热议问题