I want to do a one to many mapping that keeps order. The order itself is complex and related to business logic and does not have a single field or simple logic that can represent it.
What I want is to load an object, swap two elements (or more) in the list and save and do session.update(object)
. I expect next time the element is loaded to keep the right order however it does not.
What I am doing:
@Entity
public class Product {
@Id @GeneratedValue(strategy=GenerationType.AUTO)
private long id;
@OneToMany(fetch=FetchType.EAGER)
private List<Image> images = new ArrayList<Image>();
blah blah blah
}
@OrderColumn
did the trick for me