-->
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.  [ 1 post ] 
Author Message
 Post subject: Is it possible to query a map without a join on the parent?
PostPosted: Thu Nov 17, 2005 2:54 pm 
Newbie

Joined: Thu Nov 17, 2005 1:44 pm
Posts: 6
Hibernate version:
3.0.5

Hello,

So I have the following mapping file and what I'd like to do is build a query to get some of the indexes and elements from the attributeValues Map, based on the ID (key) and ATTRIBUTE_NAME (index) columns of the ATTRIBUTE_VALUES table, all this without a join on the ENT_SPEC_VAL table:

Code:
   <class
      name="eg.EntitySpecificationValueImpl"
      table="ENT_SPEC_VAL"
      discriminator-value="ENT_SPEC">
      
      <id name="identifier" type="long" unsaved-value="0" column="ID">
         <generator class="native"/>
      </id>
      <discriminator column="DISCR" type="string"/>
      
      <map name="attributeValues" lazy="true" table="ATTRIBUTE_VALUES" access="field">
         <key column="ID"/>
         <index column="ATTRIBUTE_NAME" type="string"/>
         <element type="eg.GenericAttributeType" not-null="true">
            <column name="VALUE"/>
         </element>
      </map>
      <subclass name="eg.ServiceSpecificationValueImpl" discriminator-value="SERV_SPEC">
      </subclass>
   </class>


I've managed to write the following HQL query that returns a list of Object[] that have the index and element values (the key and value of the Map), but this has a join between the two tables that is not (really) necessary.

Code:
select index(attribs), elements(attribs)
from eg.EntitySpecificationValue esv
join esv.attributeValues attribs
where index(attribs) in (:atVals) and esv.identifier = :id


Is there a way to do this without using a join? I would need to be able to refer to the ATTRIBUTE_VALUES.ID column in HQL, which does not seem to be possible.

So my aim is to have Hibernate generate SQL that looks like
Code:
SELECT av.attribute_name, av.value
FROM attribute_values av
WHERE av.id = ? AND av.attribute_name IN (?)

_________________
Thank you for a Great product!


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

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.