-->
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.  [ 5 posts ] 
Author Message
 Post subject: Query
PostPosted: Mon Feb 28, 2005 12:59 pm 
Newbie

Joined: Mon Feb 28, 2005 12:53 pm
Posts: 18
I have the following code :

.....
String sql = "from TABLE1 a where a.ban in " +
"( select c.ban from TABLE2 c where c.id = :id )";

sess.createQuery(sql).setLong("id", subsId.longValue()).list();

........

But when I run I get an error in parsing the sql saying an "in" is required.

Can you tell me what is wrong with this hibernate query?

Mike


Top
 Profile  
 
 Post subject: Re: Query
PostPosted: Mon Feb 28, 2005 1:09 pm 
Beginner
Beginner

Joined: Mon Nov 29, 2004 5:34 pm
Posts: 35
dpmihai wrote:
I have the following code :

.....
String sql = "from TABLE1 a where a.ban in " +
"( select c.ban from TABLE2 c where c.id = :id )";

sess.createQuery(sql).setLong("id", subsId.longValue()).list();

........

But when I run I get an error in parsing the sql saying an "in" is required.

Can you tell me what is wrong with this hibernate query?

Mike



Hi,
Change your hiberante config file, so that you can see the SQL statements. and you can find if there is problem in sql statement.

change the above one and try this one
List results = session.createQuery("from Category c " +
"where :item in (from c.items)").setEntity("item", item).list();

Let us know if it works and also send the SQL statement generated in the log/console.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 28, 2005 1:23 pm 
Newbie

Joined: Mon Feb 28, 2005 12:53 pm
Posts: 18
The following error appears :

ERROR - net.sf.hibernate.QueryException: in expected: a [ from ACCOUNTS
a where a.ban in ( select c.ban from CHEV_DISTRIBUTIONS c where c.subscriber_id
= :id )]
net.sf.hibernate.QueryException: in expected: a [from ACCOUNTS a where
a.ban in ( select c.ban from CHEV_DISTRIBUTIONS c where c.subscriber_id = :id )]

at net.sf.hibernate.hql.FromParser.token(FromParser.java:102)
at net.sf.hibernate.hql.ClauseParser.token(ClauseParser.java:87)
.........

It' s parsing error, and I do not know why. Isuppose it's something about the joining.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 28, 2005 1:31 pm 
Newbie

Joined: Fri Apr 16, 2004 9:27 am
Posts: 18
Location: Russia, Spb
It seems that your database doesn't support subselects.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 01, 2005 5:39 am 
Newbie

Joined: Mon Feb 28, 2005 12:53 pm
Posts: 18
The database used is Oracle. I doubt that it does not support subselects.
I manage to accomplish the select in two steps :

String query = "select ban from CHEV_DISTRIBUTIONS where subscriber_id=" + subsId;
rs = stm.executeQuery(query);

List bans = new ArrayList();
while(rs.next()) {
long ban = rs.getLong(1);
bans.add(new Long(ban));
}
Long[] array = new Long[bans.size()];
array = (Long[])bans.toArray(array);

Criteria crit = sess.createCriteria(Accounts.class).add(Expression.in("ban", array));
List result = crit.list();

I know that must be a simpler and better way but I did not find it. It will remain as a TODO task. If someone has an ideea how to accomplish this in only one select please tell me.

Mike


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