How could you handle the following situation using Hibernate, if at all?
( I dont actually need to do this - Im just thinking about it to check my understanding - comments would be appreciated)
An association that maintains order but does not load the entire collection on insert of new records
AFAIK if you want to have an association collection that is ordered and maintains that order when you insert new records then you have to use a
Set (or Map) and specify sort as 'natural' or provide a comparator in the hbm.
A side effect of this (for sets at least) seems to be that if the association is lazy, then inserting a new record will trigger all the persisted records to be loaded ( since the set needs to check if the new record is a duplicate ).
Ideally, though, If I dont care about duplicates, I'd like to have a ordered lazy collection that only loads all the persisted records when and if I start iterating across it, not when I insert, but the need to use a set prevents this.
I guess the ideal solution would be support for new 1.5 things like queues- specifically PriorityQueue - but in the meantime can anyone think of a way to do this?
perryn
|