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.  [ 2 posts ] 
Author Message
 Post subject: scalar functions in native SQL queries? (to_char)
PostPosted: Wed Feb 18, 2004 6:19 am 
Newbie

Joined: Wed Feb 18, 2004 5:42 am
Posts: 1
I wonder if anyone can tell me how to use a function such as to_char in Oracle in a native SQL query?

I want to execute the following query:

Select sum(t.personligtmeddelandetyp) as PERSONLI2_0_, to_char(t.skapatdatum, 'YYYY') as AVSENDARE0_, to_char(t.skapatdatum, 'MM') as MOTTAGARE0_ from personligtmeddelandesok t group by to_char(t.skapatdatum, 'YYYY'), to_char(t.skapatdatum, 'MM')

It works fine when a execute it in a SQL*plus.

When I use session.createSQLQuery with the following input

session.createSQLQuery("Select sum({t}.personligtmeddelandetyp) as {t.antal}, to_char({t}.skapatdatum, 'YYYY') as {t.ar}, to_char({t}.skapatdatum, 'MM') as {t.manad} from personligtmeddelandesok {t} group by to_char({t}.skapatdatum, 'YYYY'), to_char({t}.skapatdatum, 'MM')", "t", DialogenStatistikAntalPerManadArTO.class);

I get a SQLException with a message that a column name is illegal, since I have tried the same sql query in Sql*plus I know that tere is nothing wrong with the column names, but i suspect that it has to do with the function to_char. I know that according to the JDBC spec scalar functions should be indicated with {fn to_char(t.skapatdatum, 'YYYY')} but how do I accomplish that when hibernate expect everything between {} to be a table alias. I have tried this in normal HQL as well but there I get errors because of the scalar function in the select part of the query.

Hope that someone can tell me if my query is possible.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 18, 2004 7:20 am 
Beginner
Beginner

Joined: Tue Nov 11, 2003 4:49 am
Posts: 47
Location: Florence, Italy
You can't, please look (and vote) this issue on Jira:
http://opensource.atlassian.com/projects/hibernate/secure/ViewIssue.jspa?key=HB-673
If you need alternative ways, look at my previous posts.
Ciao.
L.

_________________
Ciao.


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