jensydney wrote:
Hi,
I'm stumped with the following (seemingly trivial) problem: I have a one-to-many association ("Order" to "Item"), and I'm using a versioning scheme for non-destructive updates -- so each object has a primary key comprised of the ID and the VERSION.
When an Order is retrieved, I'd like to have its "items" array populated with just the latest version of each Item. What is the correct association mapping for this? Do I need a nested SELECT clause?
Thanks a lot!
Jen
You could define your model a bit differently. Instead of storing all the versions of the same item in the same table (with id and version), you could have an ITEM table and ITEM_VERSION table.
An order will have a collection of items, and an item object will have collection of all its versions (lazy, if you have no use for it) and a single latest version. This is kind of like the auction example in "Hibernate in Action" where there are many bids for an item and only one of them is the winning bid.