-->
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.  [ 2 posts ] 
Author Message
 Post subject: "select distinct" objects with joined tables
PostPosted: Wed Oct 25, 2006 9:45 am 
Newbie

Joined: Mon Sep 25, 2006 8:35 am
Posts: 5
hi,
if I have two tables, Structures and Employes

<class name="Employes" table="employes">
<cache usage="read-only"/>
<composite-id name="id" class="EmployesKey">
<key-many-to-one name="structures" class="Structures">
<column name="idstruct" />
<column name="datestruct" />
</key-many-to-one>
<key-property name="codemployee" column="codemployee" type="java.lang.String"/>
<key-property name="otherkey" column="otherkey" type="java.util.Date"/>
</composite-id>
...
</class>

<class name="Structures" table="structurs">
<cache usage="read-only"/>
<composite-id name="id" class="StructuresKey">
<key-property name="idstruct" column="idstruct" type="java.lang.String"/>
<key-property name="datestruct" column="datestruct" type="java.util.Date"/>
</composite-id>

...
<set name="employesSet" inverse="true">
<key>
<column name="idstruct"/>
<column name="datestruct"/>
</key>
<one-to-many class="Employes"/>
</set>

</class>

is it possible to write a query like this?

select distinct s from Structures s, Employes e
where s.id = e.id.idstruct

I tried but I got a syntax error.
I also tried with

...where s.id.idstruct = e.id.idstruct
and s.id.datestruct = e.id.datestruct

but in this case the raised exception is "could not resolve property: idstruct of: Structures [query]"


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 25, 2006 2:05 pm 
Beginner
Beginner

Joined: Mon Nov 29, 2004 5:34 pm
Posts: 35
Hi,
Here is example, You can try with createCriteria. you can expand on this example and hope it works.


Code:


Session session = getCurrentSession();
Criteria criteria = session.createCriteria(FidsEventParameter.class);

criteria.setProjection(Projections.distinct(Projections.projectionList().add(Projections.property("terminal", "terminal").add(Projections.property("airline","airline"))).setResultTransformer(new AliasToBeanResultTransformer(FidsEventParameter.class));

List allparameterList = criteria.list();
return allparameterList;





My Forte 4GL and Spring Blog
srigold


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

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.