-->
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: Problem in Query formation
PostPosted: Tue Apr 26, 2005 4:18 am 
Newbie

Joined: Tue Apr 26, 2005 3:54 am
Posts: 3
Hibernate version: 2.0


This is the exception which I am getting
net.sf.hibernate.QueryException: aggregate function expected before ( in SELECT:


Name and version of the database you are using: MS SQL Server 2000

I am trying to use a query which is something like

select * from Employee
where emp_id = ALL(
select distinct(emp_id) from Employee
as a where a.comp_id = :compId
)

I am using the following code to convert the hibernate query to normal
sql query

Code:
QueryTranslator tl = new QueryTranslator(hql);
tl.compile((SessionFactoryImplementor) session.getSessionFactory(), new HashMap(), true);
sql = tl.getSQLString();


If any one has come across this error please do help me.
W.r.t to the error should I have a aggregate function in the select clause

Regards
Atul


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 26, 2005 4:28 am 
Beginner
Beginner

Joined: Wed Aug 04, 2004 4:33 am
Posts: 45
Location: Switzerland
I've never heard about the ALL operator. Is that something MS specific.

Replace the "= ALL" with the IN operator. I think this is what you want.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 26, 2005 4:34 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
all() is standard ANSI SQL.

That is not the problem.

The problem is that the query is not HQL. "select *"???

Read the Hibernate documentation and look at example HQL queries.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 26, 2005 4:52 am 
Newbie

Joined: Tue Apr 26, 2005 3:54 am
Posts: 3
Sorry the query is

select emp.emp_name from Employee as emp
where emp.emp_id = ALL(
select distinct(a.emp_id) from Employee
as a where a.comp_id = :compId
)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 26, 2005 4:57 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
There is no such function as distinct() in HQL or SQL.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 26, 2005 5:30 am 
Newbie

Joined: Tue Apr 26, 2005 3:54 am
Posts: 3
It worked

I just removed the bracket

select emp.emp_name from Employee as emp
where emp.emp_id = ALL(
select distinct a.emp_id from Employee
as a where a.comp_id = :compId
)


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.