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: Error in a query with "in" clause
PostPosted: Mon Sep 25, 2006 8:55 am 
Newbie

Joined: Mon Sep 25, 2006 8:35 am
Posts: 5
hi,
Im a newbie with hibernate. I must invoke the createquery method to fill query result into an array. my code is as follows

protected Vector getResultArray(Session session, String query){
...
Vector vec=new Vector();
Transaction tx=null;

try
{
tx = session.beginTransaction();
vec=new Vector(session.createQuery(query).setReadOnly(true).list());
tx.commit();
}
catch (Exception e)
{
if (tx!=null) tx.rollback();
.....
}
return vec;
}


and this is the query passed to it

String query="select f.surname, f.name, f.code from Employees as f " +
"where f.code in (" +
"select distinct(i.code) from Employeeroles as i " +
"where i.descrole <> 'EMPLOYEE') " +
"and (f.name like '"+filter.toUpperCase()+"%' or f.surname like '"+filter.toLowerCase()+"%')" +
"order by f.surname, f.name";

when I call getResultArray(session, query) I get this error

could not resolve property: code of: [select f.surname, f.name, f.code from [path.to.database.]Employees as f where f.code in (select distinct(i.code) from [path.to.database.]Employeeroles as i where i.descrole <> 'EMPLOYEE') and (f.name like '%%' or f.surname like '%%') order by f.surname, f.name]

where is the error? I tried to run query and it works. Please help


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 25, 2006 10:45 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
You can't write:
Code:
select distinct(i.code)

write simply:
Code:
select distinct i.code


Please, don't forget to rate.


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.