When retrieving values from DB hibernate does not keep insertion order in collections of type Set
but keeps it in List
collections. I've tried to specify LinkedHashSet
manually but it does not help.
I have below parent entity
@Entity
@Table(name = "radio")
@PrimaryKeyJoinColumn(name = "id", referencedColumnName = "id")
public class Radio extends AbstractField {
@OneToMany(cascade = CascadeType.ALL)
@JoinColumn(name = "radio_id")
private Set<Choice> choices = new LinkedHashSet<>();
}
And child entity:
@Entity
@Table(name = "choice")
public class ChoiceEntity {
@Id
@GeneratedValue
@Column(name = "id", nullable = false)
private UUID id;
@Column(name = "value")
private String value;
}
When I am retriving values from the DB, hibernate stores them in choices
collection in random order. When I've changed collection type to use List
everything works fine.
Is it possible to configure hibernate to keep DB order in the collections of type Set
without using any addition order_row
.