-->
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.  [ 3 posts ] 
Author Message
 Post subject: How to use where in <set>s
PostPosted: Tue Jan 24, 2006 6:40 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
I can't find any explanation of the where attribute in the ref docs or HIA. I'd like to know the syntax available to me in a collection's where clause.

I have an entity (Installation) with a date range, containing a Meter and collection of that meter's Configurations, which also have date ranges. The Set of Configurations will be the Configurations of the Meter whose date ranges overlap with the Installation's date range. So in Installation's mapping I want something like
Code:
<set name="Configs" table="Configuration"
  where="inst.StartDateTime < config.EndDateTime and inst.EndDateTime > config.StartDateTime">
    <key column="MeterID" property-ref="MeterID"/>
    ...
  </set>

How do I get a reference to the parent entity (inst) and nested entity (config) into the where attribute?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 24, 2006 11:30 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
subquery

Code:
<set name="Configs" table="Configuration"
  where="(select StartDateTime from Installation inst where inst.MeterID = Configuration.MeterID) < Configuration.EndDateTime and (select EndDateTime from Installation inst where inst.MeterID = Configuration.MeterID) > Configuration.StartDateTime"
>
    <key column="MeterID" property-ref="MeterID"/>
    ...
</set>


If the set is a many-to-many, you'd probably need to move this where attribute to the <many-to-many/> element and tweak it to account for the association table.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 24, 2006 11:38 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Fair enough. It's a bit inefficient though, especially seeing as the generated SQL has those table aliases in it, so they could be accessible fairly easily.
Would adding support for aliases to that where clause be major work? Perhaps something like {parent} and {element}. There are quite a few attributes in various elements with simple SQL (order-by, where, subselect, etc.) which would be able to benefit from a few standard aliases like that. If it's a reasonable request I could add a JIRA issue about it.


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