-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: One-to-many association to LATEST VERSION of object
PostPosted: Thu Jan 26, 2006 5:22 am 
Beginner
Beginner

Joined: Sat May 07, 2005 12:01 pm
Posts: 33
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


Top
 Profile  
 
 Post subject: Re: One-to-many association to LATEST VERSION of object
PostPosted: Thu Jan 26, 2006 8:19 am 
Beginner
Beginner

Joined: Sun Jan 22, 2006 6:56 am
Posts: 29
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.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 26, 2006 6:10 pm 
Beginner
Beginner

Joined: Sat May 07, 2005 12:01 pm
Posts: 33
Thanks, but I'm only intertested in the most recent version -- from the application's perspective, none of the older versions exist. I just need to store them in the db for archival purposes.

jen


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 26, 2006 6:26 pm 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
jensydney wrote:
Thanks, but I'm only intertested in the most recent version -- from the application's perspective, none of the older versions exist. I just need to store them in the db for archival purposes.

jen


Does your database support updatable Views ?

_________________
Preston

Please don't forget to give credit if/when you get helpful information.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 26, 2006 8:12 pm 
Beginner
Beginner

Joined: Sat May 07, 2005 12:01 pm
Posts: 33
No, I don't want to rely on db capabilities. I'd prefer to accomplish this with Hibernate constructs.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 26, 2006 8:28 pm 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
jensydney wrote:
No, I don't want to rely on db capabilities. I'd prefer to accomplish this with Hibernate constructs.


Check out the Section in the docs about Custom SQL Loading
It's 16.5 in the 3.1 docs

_________________
Preston

Please don't forget to give credit if/when you get helpful information.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.