-->
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.  [ 4 posts ] 
Author Message
 Post subject: Can I use to_char with Hibernate?
PostPosted: Thu Mar 04, 2004 7:23 pm 
Pro
Pro

Joined: Wed Oct 08, 2003 10:31 am
Posts: 247
I'm using Hibernate 2.1.1 and Postgres 7.4.1.
I want to use the to_char function inside a query to retrieve the day of a date.
Is it possible?
I've tried using "session.createSQLQuery()" but keeps giving me:

net.sf.hibernate.QueryException: undefined alias: to_char ...


Does Hibernate support this kind of function in a query?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 04, 2004 11:05 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
You could read the date as a java.util.Date (or timestamp etc) and get the day from the Java Class.

I don't know Postgres syntax but in HQL the to_date() function is not valid in the select clause as its an unknown function in the dialect (see Oracle as an example).


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 05, 2004 6:16 am 
Pro
Pro

Joined: Wed Oct 08, 2003 10:31 am
Posts: 247
david wrote:
You could read the date as a java.util.Date (or timestamp etc) and get the day from the Java Class.

I don't know Postgres syntax but in HQL the to_date() function is not valid in the select clause as its an unknown function in the dialect (see Oracle as an example).


Thanks for the reply David.
I know the workarround. Just want to know if Hibernate supports functions like to_char in queries.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 06, 2004 7:47 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Assuming to_char() is valid for postgress it will accept it in the where clause. In the select clause it will need to be added to the Postgress Dialect (depending on the arguments). v2.2 have have improved parser that will help in this area.


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