-->
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: cannot get distinct results for query
PostPosted: Wed Jul 11, 2007 6:40 pm 
Newbie

Joined: Tue Jun 27, 2006 2:51 pm
Posts: 14
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


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.