-->
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.  [ 3 posts ] 
Author Message
 Post subject: using the lower() function
PostPosted: Tue Apr 06, 2004 8:08 am 
Newbie

Joined: Tue Apr 06, 2004 7:40 am
Posts: 2
version: Hibernate-2.1...

query run though my webapp:

HQL: select con.gender, count(con) from ConsumerBrand cb join cb.brand b join cb.consumer con group by con.gender

SQL: select consumer2_.gender as x0_0_, count(consumer2_.consumer_id) as x1_0_
from consumer_brand consumer0_
inner join brand brand1_ on consumer0_.brand_id=brand1_.brand_id
inner join consumer consumer2_ on consumer0_.consumer_id=consumer2_.consumer_id group by consumer2_.gender

returns:
X: female : 20
X: male : 69
X: Male : 2
X: null : 9

Now, I want to group 'male' and 'Male' together...

so, if I execute the SQL below in psql:

SQL: select lower(consumer2_.gender) as x0_0_, count(consumer2_.consumer_id) as x1_0_
from consumer_brand consumer0_
inner join brand brand1_ on consumer0_.brand_id=brand1_.brand_id
inner join consumer consumer2_ on consumer0_.consumer_id=consumer2_.consumer_id group by lower(consumer2_.gender)

returns:
X: female : 20
X: male : 71
X: null : 9

so now I write the following HQL in my webapp:

select lower(con.gender), count(con) from ConsumerBrand cb join cb.brand b join cb.consumer con group by lower(con.gender)

returns:
net.sf.hibernate.QueryException: undefined alias: lower [select lower(con.gender), count(con) from za.co.vine.consumerManagement.binding.hibernate.ConsumerBrand cb join cb.brand b join cb.consumer con group by lower(con.gender)]
at net.sf.hibernate.hql.PathExpressionParser.token(PathExpressionParser.java:110)
at net.sf.hibernate.hql.ParserHelper.parse(ParserHelper.java:29)
at net.sf.hibernate.hql.SelectParser.token(SelectParser.java:153)
at net.sf.hibernate.hql.ClauseParser.token(ClauseParser.java:87)
at net.sf.hibernate.hql.ClauseParser.end(ClauseParser.java:114)
at net.sf.hibernate.hql.PreprocessingParser.end(PreprocessingParser.java:140)
at net.sf.hibernate.hql.ParserHelper.parse(ParserHelper.java:30)
at net.sf.hibernate.hql.QueryTranslator.compile(QueryTranslator.java:146)
at net.sf.hibernate.hql.QueryTranslator.compile(QueryTranslator.java:133)
at net.sf.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:352)
at net.sf.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:330)
at net.sf.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:1368)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1332)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1322)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1314)
at za.co.vine.consumerManagement.helpers.ConsumerManagementFactory.getGendersQuery(ConsumerManagementFactory.java:1915)
at za.co.vine.consumerManagement.Manager.getGendersQuery(Manager.java:138)
at za.co.vine.consumerManagement.test.TestManager.<init>(TestManager.java:75)
at za.co.vine.consumerManagement.test.TestManager.main(TestManager.java:139)
za.co.vine.consumerManagement.RecoverableConsumerManagementException: undefined alias: lower [select lower(con.gender), count(con) from za.co.vine.consumerManagement.binding.hibernate.ConsumerBrand cb join cb.brand b join cb.consumer con group by lower(con.gender)]
at za.co.vine.consumerManagement.helpers.ConsumerManagementFactory.getGendersQuery(ConsumerManagementFactory.java:1933)
at za.co.vine.consumerManagement.Manager.getGendersQuery(Manager.java:138)
at za.co.vine.consumerManagement.test.TestManager.<init>(TestManager.java:75)
at za.co.vine.consumerManagement.test.TestManager.main(TestManager.java:139)



Any ideas?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 06, 2004 8:21 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
Looks like some limitation in hsql, but you can do it better:

UPDATE consumer_brand set gender = lower(con.gender);

and create a trigger to validate data.


Top
 Profile  
 
 Post subject: Re
PostPosted: Tue Apr 06, 2004 8:35 am 
Newbie

Joined: Tue Apr 06, 2004 7:40 am
Posts: 2
thanks for the help.

Korak


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