-->
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.  [ 4 posts ] 
Author Message
 Post subject: How can I express this in Criteria
PostPosted: Thu Mar 05, 2009 5:09 pm 
Newbie

Joined: Wed Sep 10, 2008 2:47 pm
Posts: 8
I need to express the following HQL using Criteria:

from filter4 where filter1.filter2.inttest=10

I have tried these alternatives with no success:

Criteria criteria = session.createCriteria("filter4");
criteria.createAlias("filter1", "filter1");
criteria.createAlias("filter1.filter2", "filter2");

criteria.add(Restrictions.conjunction()
.add(Restrictions.eq("filter2.inttest","10"))
);
criteria.list();


And:

Criteria criteria = session.createCriteria("filter4");
criteria.createAlias("filter1.filter2", "a");

criteria.add(Restrictions.conjunction()
.add(Restrictions.eq("a.inttest","10"))
);

criteria.list();


Your help would be greatly appreciated.


Last edited by jmpeace on Thu Mar 05, 2009 5:32 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 05, 2009 5:24 pm 
Beginner
Beginner

Joined: Wed Oct 03, 2007 4:10 am
Posts: 46
Criteria criteria = session.createCriteria("filter4");
criteria.createAlias("filter1", "filter1");
criteria.createAlias("filter1.filter2", "filter2");

criteria.add(Restrictions.conjunction()
.add(Restrictions.eq("filter2.inttest","10"))
);
criteria.list();

it has to work if you have
in filter4 mapping many-to-one filter1
and in filter1 mapping many to one filter2


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 05, 2009 5:40 pm 
Newbie

Joined: Wed Sep 10, 2008 2:47 pm
Posts: 8
Thanks for your answer alexandrubarbat, these are my mappings. (I have the mappings you said.)

<class entity-name="filter1" table="filter1" dynamic-insert="true" dynamic-update="true">
<id name="id" type="string" column="id">
<generator class="uuid" />
</id>
<many-to-one name="filter2" class="filter2" lazy="false"
fetch="join" not-null="false" />
</class>
<class entity-name="filter2" table="filter2" dynamic-insert="true"
dynamic-update="true">
<id name="id" type="string" column="id">
<generator class="uuid" />
</id>
<property name="inttest" column="inttest" not-null="false"
type="int" unique="false" />
</class>
<class entity-name="filter4" table="filter4" dynamic-insert="true"
dynamic-update="true">
<id name="id" type="string" column="id">
<generator class="uuid" />
</id>
<many-to-one name="filter1" class="filter1" lazy="false"
fetch="join" not-null="false" />
</class>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 05, 2009 5:43 pm 
Newbie

Joined: Wed Sep 10, 2008 2:47 pm
Posts: 8
I found the problem,

"10" should be just 10, as the inttest column is of type int.

Thanks again alexandrubarbat.


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