-->
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.  [ 6 posts ] 
Author Message
 Post subject: HQL problem
PostPosted: Fri Jul 28, 2006 7:23 am 
Beginner
Beginner

Joined: Thu Apr 20, 2006 11:51 am
Posts: 44
Hibernate version:last

Hello I've a big problem with my a HQL query.
I want that my query returns all the CV with a given 'lastname' and a given 'state' of the Result.
CV has a set of Result called 'resultList'.
My query is like


List cvListByname = new ArrayList();
Query q = session.createQuery("from CV where lastname =:lastname and resultList.state = :state");
q.setParameter("lastname", lastname);
q.setParameter("state", new Integer(1));
cvListByname = q.list();


cvListByname now contains the CV with the resultList but the resultList contains also the 'Result' 's with state != 1.

Someone can help me?
thanks a lot
Martina






Mapping documents:

<class
name="com.sintesinet.jobnet.imatch.cv.model.CV"
table="JN_CV"
>

<id
name="cvID"
column="cvID"
type="long"
>
<generator class="native">
<!--
To add non XDoclet generator parameters, create a file named
hibernate-generator-params-CV.xml
containing the additional parameters and place it in your merge dir.
-->
</generator>
</id>

<set
name="resultList"
lazy="true"
cascade="none"
sort="unsorted"
>

<key
column="cvId"
>
</key>

<one-to-many
class="com.sintesinet.jobnet.imatch.cv.model.Result"
/>

</set>

<property
name="address"
type="java.lang.String"
update="true"
insert="true"
column="address"
/>

<property
name="email"
type="java.lang.String"
update="true"
insert="true"
column="email"
/>

<property
name="lastname"
type="java.lang.String"
update="true"
insert="true"
column="lastname"
/>

<property
name="mailInfoID"
type="long"
update="true"
insert="true"
column="mailInfoID"
/>

<property
name="name"
type="java.lang.String"
update="true"
insert="true"
column="name"
/>

<property
name="data"
type="java.util.Date"
update="true"
insert="true"
column="data"
/>

<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-CV.xml
containing the additional properties and place it in your merge dir.
-->

</class>



<class
name="com.sintesinet.jobnet.imatch.cv.model.Result"
table="JN_RESULT"
>

<id
name="id"
column="id"
type="long"
>
<generator class="foreign">
<param name="property">points</param>
<!--
To add non XDoclet generator parameters, create a file named
hibernate-generator-params-Result.xml
containing the additional parameters and place it in your merge dir.
-->
</generator>
</id>

<property
name="cvId"
type="long"
update="true"
insert="true"
column="cvID"
/>

<property
name="mansioneId"
type="long"
update="true"
insert="true"
column="mansioneID"
/>

<property
name="state"
type="int"
update="true"
insert="true"
column="state"
/>

<one-to-one
name="points"
class="com.sintesinet.jobnet.imatch.cv.model.Points"
cascade="all"
outer-join="auto"
constrained="true"
/>

<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-Result.xml
containing the additional properties and place it in your merge dir.
-->

</class>


<class
name="com.sintesinet.jobnet.imatch.cv.model.Points"
table="JN_POINTS"
lazy="false"
>

<id
name="id"
column="id"
type="long"
>
<generator class="native">
<!--
To add non XDoclet generator parameters, create a file named
hibernate-generator-params-Points.xml
containing the additional parameters and place it in your merge dir.
-->
</generator>
</id>

<property
name="competenzePoint"
type="float"
update="true"
insert="true"
column="competenzePoint"
/>

<property
name="motivazioneMult"
type="float"
update="true"
insert="true"
column="motivazioneMult"
/>

<property
name="skillPoint"
type="float"
update="true"
insert="true"
column="skillPoint"
/>

<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-Points.xml
containing the additional properties and place it in your merge dir.
-->

</class>


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 28, 2006 5:46 pm 
Newbie

Joined: Fri Oct 14, 2005 4:42 pm
Posts: 15
Try using a ResultTransformer and CriteriaQuery, as described here:

http://www.hibernate.org/hib_docs/v3/re ... sociations


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 02, 2006 5:30 am 
Beginner
Beginner

Joined: Thu Apr 20, 2006 11:51 am
Posts: 44
Yes but
Is possible if I've

(Person) 1 ---------> * (Address) ?

I want to take a List of object 'Person' that have inside only the Address where the Address.country_code == 02022 ??

It's possible to retrive a List of Person with inside only the Address that specifies any condition?

Someone can give me an example?
Thanks a lot guys
Martina


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 02, 2006 5:32 am 
Expert
Expert

Joined: Thu Sep 22, 2005 10:29 am
Posts: 285
Location: Almassera/Valencia/Spain/EU/Earth/Solar system/Milky Way/Local Group/Virgo Supercluster
NO


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 02, 2006 10:04 am 
Beginner
Beginner

Joined: Thu Apr 20, 2006 11:51 am
Posts: 44
Hello thanks for your response
so what I've to do?
2 different queries and iterate the 1st result List?
thanks


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 02, 2006 2:10 pm 
Expert
Expert

Joined: Thu Sep 22, 2005 10:29 am
Posts: 285
Location: Almassera/Valencia/Spain/EU/Earth/Solar system/Milky Way/Local Group/Virgo Supercluster
I'd make resultList a bidirectional association. So you'd only need one query.
Code:
String hql = "select result from CV cv inner join cv.resultList result where cv.lastname =:lastname and result.state = :state";
Query q = session.createQuery(hql)
   .setParameter("lastname", lastname)
   .setParameter("state", new Integer(1));
List resultListByname = resultListByname = q.list();

resultListByName will hold Result objects. But every Result object will have a reference to their CV object.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.