Alex Rivera | Logout

Saving order of a List in JPA

Asked 2010-04-15T08:09:46.997
33

I have the following question about JPA:

Can I save the order of the elements in a java.util.List? In my application the order in which I put elements in the Lists is important but after I get those collections from the database the order is not the same (as expected). Can you show me a way to deal with this problem?

P.S. There is not a field in the entities that I put in the collections by which I can order them.

Rosen

Edit
Report

1 Answer

40

There are some hacky ways of doing this in JPA 1, but it's easiest to switch to a JPA 2 provider. The @OrderColumn annotation support is what you're looking for. Eclipselink have an ok tutorial on how to use it.

answered 2010-04-15T08:13:54.133

Your Answer