Quote:
I want to maintain the insertion order of the keys.
My guess is you would have to store this information in the DB and then while retrieving orderby that column. Essentially simulate the @OrderColumn behavior (which I guess would not work in your case since you use a Map and not a List). So for example:
Code:
…
Users u = new Users();
u.setUsername("foo");
Map<Integer, Addresses> m = new LinkedHashMap<Integer, Addresses>();
Addresses addr = new Addresses();
addr.setCity("Jersey City");
addr.setZip(07302);
addr.setPosition(1);
m.put(addr.getZip(), addr);
Addresses addr = new Addresses();
addr.setCity("NYC");
addr.setZip(11011);
addr.setPosition(2);
m.put(addr.getZip(), addr);
u.setAddresses(m);
…
In your User entity:
Code:
@ElementCollection
@CollectionTable(name="ADDRESSES", joinColumns={@JoinColumn(name="user_id")})
@MapKeyColumn(name="ZIP")
@OrderBy("position asc")
public Map<Integer, Addresses> getAddresses() {
return addresses;
}
Of course, for this to work you'd need the position attribute in the addresses entity.
HTH.