HiLo generator strategy not working
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;
}
}
If we are using mysql it would be better to use the @GenericGenerator of increment strategy.
- sequence - This sort of strategy supports by Oracle, Postgresql.
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<Address> 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.
Hilo is not supported anymore, this should work
@GenericGenerator(name="sequence-gen",strategy="sequence")