Hi Guys,
For the life of me, I can't seem to get unique results from my query. Per the mapping snippets below, a model contains many trims, which in turn contain many accessories. For a given model, I want a unique list of its accessories, pretty straight-forward concept, but I'm not having any luck. Mappings are below and I've tried the 2 following approaches:
Code:
String hql = "select distinct a from Accessory a " +
"join a.trim t " +
"join t.model m " +
"where m.modelId = :modelId";
return getHibernateTemplate().findByNamedParam(hql, "modelId", modelId);
and
Code:
Criteria accCrit =
getSession().createCriteria(Accessory.class)
.createCriteria("trim")
.createCriteria("model")
.add(Restrictions.eq("modelId", new Integer(modelId)))
.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
return accCrit.list();
Any help would be greatly appreciated. Thanks!
Hibernate version: hibernate 3
Mapping documents:Model:
Code:
<class name="Model" table="mmsaBPModel">
...
<set name="trims" table="mmsaBPTrim" inverse="true">
<cache usage="read-write" region="standardCache"/>
<key column="ModelId"/>
<one-to-many class="Trim"/>
</set>
Trim:
Code:
<class name="Trim" table="mmsaBPTrim">
...
<set name="accessories" table="mmsaBPTrimAccessoryPrice" inverse="true">
<key column="TrimId"/>
<one-to-many class="Accessory"/>
</set>
Accessory:
Code:
<class name="Accessory" table="mmsaBPTrimAccessoryPrice">
...
<many-to-one
name="trim"
class="Trim"
column="TrimId"
insert="false"
update="false"
/>
Name and version of the database you are using:
Sql Server 2005