-->
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: How to make a "IN" subselect with criteria?
PostPosted: Tue Aug 07, 2007 3:42 am 
Newbie

Joined: Fri Aug 03, 2007 9:35 am
Posts: 8
Hi, I'm not able to do something like this

select * from A where A.Id in (select id from B)

I have:
TABLE Job
int IdJob

TABLE JobPerson (association table)
int IdJob
int IdPerson

I need all jobs made by requestedPerson (this person has IdPerson=2).

I need to build the query with criteria. I tried this:

DetachedCriteria subquery = DetachedCriteria.For(typeof(JobPerson));
subquery.Add(Expression.Eq("IdPerson", requestedPerson.IdPersonGet));
subquery.SetProjection(Projections.Property("IdJob"));

ICriteria critMain = session.CreateCriteria(typeof(Job));
critMain.Add(Subqueries.In("IdJob", subquery));
IList jobs = critMain.List();


But it result to exception: {"Failed to convert parameter value from a String to a Int32."}

{"could not execute query
[ SELECT this_.IdJob as IdJob11_0_, this_.Name as Name11_0_, this_.IdPath as IdPath11_0_, this_.IdPersonHolder as IdPerson4_11_0_, this_.IdPersonHolderHistory as IdPerson5_11_0_ FROM Job this_ WHERE ? in (SELECT this_0_.IdJob as y0_ FROM JobPerson this_0_ WHERE this_0_.IdPerson = ?) ]
Positional parameters:
0 IdJob
0 2
[SQL: SELECT this_.IdJob as IdJob11_0_, this_.Name as Name11_0_, this_.IdPath as IdPath11_0_, this_.IdPersonHolder as IdPerson4_11_0_, this_.IdPersonHolderHistory as IdPerson5_11_0_ FROM Job this_ WHERE ? in (SELECT this_0_.IdJob as y0_ FROM JobPerson this_0_ WHERE this_0_.IdPerson = ?)]"}


What did I wrong???


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 09, 2007 12:01 pm 
Expert
Expert

Joined: Fri May 13, 2005 11:13 am
Posts: 292
Location: Rochester, NY
Instead of Subqueries.In(), use Subqueries.PropertyIn().

Good luck!


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.