-->
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: how can HQL return a function value
PostPosted: Tue Aug 24, 2004 2:51 am 
Newbie

Joined: Tue Aug 24, 2004 2:17 am
Posts: 4
Hibernate version:2.1.5
Name and version of the database you are using:SQL Server 2000

Hello,

I am trying to convert the following SQL Server query to HQL:
select datepart(hour, record_date), event_id, count(*) from raw_tb group by datepart(hour, record_date) , event_id

I test the following HQL works with no problem:
Select rawTb.eventId from RawTb rawTb group by {fn HOUR(rawTb.recordDate)}, rawTb.eventId

but fails for the following HQL:
Select {fn HOUR(rawTb.recordDate)}, rawTb.eventId from RawTb rawTb group by {fn HOUR(rawTb.recordDate)}, rawTb.eventId

Can anyone tell me how to correct the HQL? thanks.

Full stack trace of any exception that occurs:

DAOException: net.sf.hibernate.QueryException: undefined alias: {fn [Select {fn HOUR(rawTb.recordDate)}, rawTb.eventId from RawTb rawTb group by {fn HOUR(rawTb.recordDate)}, rawTb.eventId]
at net.sf.hibernate.hql.PathExpressionParser.token(PathExpressionParser.java:103)
at net.sf.hibernate.hql.ParserHelper.parse(ParserHelper.java:29)
at net.sf.hibernate.hql.SelectParser.token(SelectParser.java:154)
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:143)
at net.sf.hibernate.hql.ParserHelper.parse(ParserHelper.java:30)
at net.sf.hibernate.hql.QueryTranslator.compile(QueryTranslator.java:149)
at net.sf.hibernate.hql.QueryTranslator.compile(QueryTranslator.java:138)
at net.sf.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:293)
at net.sf.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:1530)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1501)
at net.sf.hibernate.impl.QueryImpl.list(QueryImpl.java:39)
.......


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 24, 2004 3:41 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
have you tried mapping this call to a formula attribute?

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 24, 2004 3:56 am 
Newbie

Joined: Tue Aug 24, 2004 2:17 am
Posts: 4
First thanks for the help.

I think what you mention is the reason why it fails. I just learn from the forum how to map a database function with one parameter like this:

public class MySQLServerDialect extends SQLServerDialect {
public MySQLServerDialect() {
super();
registerFunction("month", new SQLFunction() {
public Type getReturnType(Type columnType, Mapping mapping) {
return Hibernate.INTEGER;
}
public boolean hasArguments() {
return true;
}
public boolean hasParenthesesIfNoArguments() {
return true;
}
});
}

but I just don't know how to map {fn} and also how to map functions with more than 1 arguement. such as datepart(hour, xx). Since SQL Server only have month, year, day functions but no hour, minute, second function, I don't know what I can do.


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.