-->
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: Problem with Select Distinct query
PostPosted: Thu Sep 01, 2005 11:40 am 
Newbie

Joined: Thu Sep 01, 2005 10:34 am
Posts: 2
Is it possible to do a Select Distinct on a computed column using HQL ?

I have the following perfectly valid SQL statement :

SELECT DISTINCT zp.zipCode / 100 from ZipCodes zp Where zp.referenceId = 200;

I try the same thing in as HQL :

SELECT DISTINCT zp.zipCode / 100 from ZipCodes as zp Where zp.referenceId = 200;

and I get the following error :

net.sf.hibernate.QueryException: , expected in SELECT [SELECT DISTINCT zp.zipCode/100 From ......]

If I change the query to

SELECT DISTINCT zp.zipCode from ZipCodes as zp Where zp.referenceId = 200;

It works like a charm, although the resulting Collection is not at all what I want.


We are using Hibernate 2.1.7.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 01, 2005 4:07 pm 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
work perfectly in hibernate 3

try this :

SELECT DISTINCT (zp.zipCode / 100) from ZipCodes zp Where zp.referenceId = 200;

or upgrade to hibernate 3

I haven't hiberante2 for test


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 01, 2005 4:29 pm 
Newbie

Joined: Thu Sep 01, 2005 10:34 am
Posts: 2
I've been there already. Hibernate doesn't parse it correctly with the parens.

Migrating the application to use Hibernate 3 is not an option for the current release.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 01, 2005 4:42 pm 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
I think that hibernate developer don't work on hibernate2 and if it doesn't work then ...


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 01, 2005 4:48 pm 
Beginner
Beginner

Joined: Mon Sep 27, 2004 4:28 pm
Posts: 44
I don't know if you're ready to think about workarounds yet.. but since you say you can't upgrade, once possibility might be to create an extra column in your database (or a view, if this is a read-only table) to provide you the zipcode / 100.

Anyways. Maybe I'm stating the obvious. That said, I just finished the migration to 3 from 2.1.7 and it went much smoother than I thought it would.


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.