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 (?)