-->
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: mathematical expressions in HQL select clause
PostPosted: Tue Dec 14, 2004 9:47 am 
Beginner
Beginner

Joined: Wed Sep 24, 2003 11:16 am
Posts: 20
Location: Turkey
Hibernate version: hibernate-2.1.4
Name and version of the database you are using: PostgreSQL 8.0b

I have searched hibernate documentations and faq's and this forum but still couldn't figure out how can (or if I can) use mathematical expressions in HQL select clause like it is done in SQL select clauses.

I want to make a query like this:

select (1/suggestion.numberOfAuthors) from Suggestion as suggestion

Is it possible, and how?

Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 14, 2004 11:31 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Did you try it?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 14, 2004 12:16 pm 
Beginner
Beginner

Joined: Wed Sep 24, 2003 11:16 am
Posts: 20
Location: Turkey
of course, i've tried, it didn't run giving:
aggregate function expected before ( in SELECT [select (1 / suggestion.numberOfAuthors) from ots.domain.Suggestion as suggestion]

when i change the query into this

select sum(1/suggestion.numberOfAuthors) from Suggestion as suggestion

it worked. in fact this was what i wanted. i was just trying withot aggregate functions before it gets too complicated.

now again there seems to be some problem with mathematical expressions in select clause. when i try to use a value that is returned by a subquery in select clause:

select sum(1.0 / (select size(suggestion2.authors) from Suggestion as suggestion2 where suggestion2=suggestion)), personnel.department from Suggestion as suggestion join suggestion.authors as suggestion_author join suggestion_author.personnel as personnel join personnel.department as dept group by dept

The error message given is:
net.sf.hibernate.QueryException: ( expected before ) in select [select sum(1.0 / (select ....


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 14, 2004 12:20 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Probably not yet possible. The new Parser in H3 will improve a lot there, so if you can't get it to work, wait for some more advanced H3 versions.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 14, 2004 7:52 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
The classic parser cannot deal with constants and cannot deal with expressions using operators in the select clause. H3's antler based parser will make this much easier to add in the future.


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.