Friday, May 25, 2007

JPA list ordering quirk

Seems JPA has one of those quirks which just doesn't make Java sense. It seems that in the JPA specification, there is no preservation of list ordering, except on attributes based on the target object. The order of a list should not be tied to attributes on that list. Though it makes database sense, a lists state is independent of the contained objects in the Java world and thus it should be true also when using lists in JPA... I'm sure there were reasons for doing it this way, but it's kinda dumb.

JPA implementations usually create a many to many table for the join here anyway, so all it would have needed is an extra attribute identifying the order of the list.

Maybe I'm asking a lot, but I would have thought this would be taken as a given. As a side note, I am glad to find the Pro EJB 3: JPA book by Mike Keith and Merrick Schincariol covered this topic very well when I looked it up. Somehow Googling for "JPA list order" just didn't come up with anything very clear.

0 comments: