I'm trying to map a collection/List of Stations onto a Route. From Route, the relationship is @OneToMany (or @ManyToMany if stations can be used by more than one route?)
It is crucial that the order of the stations is maintained when users add/remove/shuffle stations after the station list has originally been specified.
eg: if a route is originally specified as "Waterloo, Embankment, Leicester Square, Heathrow, Edgware", users should be able to perform the following operations on the list (my API is simplified for illustrative purposes):
Code:
////////////////////////////////
insert(0, "Kennington");
insert(3, "Charing Cross");
delete("Heathrow");
append("Tottenham Court Road");
append("Goodge Street");
move(LAST,"Edgware");
em.merge(route);
////////////////////////////////
I think I'll need to use a join table, but what's the best way to get Hibernate (JPA) to ensure that the station PKs are stored/fetched in the correct order?