-->
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.  [ 2 posts ] 
Author Message
 Post subject: one-to-one mapping on a one-to-many relationship
PostPosted: Wed Jan 02, 2008 6:15 pm 
Newbie

Joined: Wed Nov 21, 2007 1:35 pm
Posts: 2
This is similar to the issue in Java Persistence with Hibernate where there is a one-to-many relationship from item to bid as well as a one-to-one relationship between them on successful bid. In section 8.1.2, "Arbitrary join conditions with formulas" the single row is identified by a single property, "SUCCESSFUL".

My situation is that I also have a one-to-many relationship between two tables but I need to restrict the many to a single, currently effective row which is determined by testing "eff_ts = exp_ts" on the many side. The columns involved are timestamps.

I've tried variations on the <properties> and <formula> tags specifying the 1:m surrogate key join and sql on the two columns in the same, single row but with no luck.

The sql would be: "select b.beta_id from alpha a, beta b where a.alpha_id = b.alpha_id and b.eff_ts = b.exp_ts"

I already have the set of b instances loading into the alpha object, I just need the single, current beta object of the set as a one-to-one mapping.

_________________
... and this too shall be deprecated


Top
 Profile  
 
 Post subject: solution
PostPosted: Thu Jan 03, 2008 4:07 pm 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
In your posting it is unclear if you already have a mapping that you can't change (and therefore you are asking for code help on how to handle the problem), or you can change your mapping file and are asking for help on that.

If your mapping can't change, you can retrieve the "a" along with a collection of multiple "bs" and then apply a filter on the collection. Or you can write HQL .

If you want to change the mapping files, you can use a formula (a simple formula, don't complicate yourself with joins), or you can create a "subselect entity" for B, containing only the items that comply with that "ts" condition. The latter sounds like the most valuable solution to me, business-wise.

_________________
Gonzalo Díaz


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.