Hibernate 3.0.5
I have a class List that has a collection of ListValue objects. Based upon all of my reading, I decided that it is reasonable to map this collection of ListValue objects as a value type, as follows, using an <idbag> since the legacy database uses surrogate key for the ListValues table.
<class name="List" table="List">
<id name="id" type="long">
<column name="ListID" not-null="true"/>
<generator class="identity"/>
</id>
<property name="listName" type="string" column="ListName" not-null="true">
<property name="numericKey" type="boolean" column="NumericKey"/>
<idbag name="listValues" table="ListValues">
<collection-id type="Long" column="ID">
<generator class="sequence"/>
</collection-id>
<key column="ListID"/>
<composite-element class="ListValue">
<property name="valueKey" column="ValueKey"/>
<property name="valueDesc" column="ValueDesc"/>
<property name="orderId" column="OrderID"/>
</composite-element>
</idbag>
</class>
The problem is that I want to retrieve List objects with their ListValue objects ordered in more than one way. So I don't want to put an "order-by" in the <idbag> in the class mapping because there is no single ordering that applies for all retrievals. Instead, I am doing the ordering in queries, such as the following:
<query name="GenericListValueQuery"><![CDATA[
select new LabelValueBean(lv.ValueDesc, lv.ValueKey)
from List list
join list.listValues lv
where list.listname = :listName
order by lv.valueDesc
]]></query>
However, this results in a MappingException: class ListValue not found while l\ooking for property: valueKey
I believe this is because the ListValue class is not mapped. Only the List class is mapped, and the ListValue class is mapped as a collection of value types in the List class mapping. From the docs, it does not appear to me that the table containing the collection of value types should be explicity mapped, or ?
So how can I execute various queries to obtain a List with its ListValue objects in different orders ?
Should I scrap the collection of value type approach and just go with entity association mapping, even though the relationship suggests a collection of value types ?
thx.
|