-->
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: SQL Extensions
PostPosted: Thu Oct 28, 2004 12:01 pm 
Newbie

Joined: Thu Oct 28, 2004 10:23 am
Posts: 1
I want to know how SQL Extensions can be used with Hibernate. I need to use "year" and "month" functions. My HQL is like this:

select {fn YEAR(e.date)}, {fn MONTH(e.date)} from MyObject as e where not e.date is null

I've seen in previous forum messages that this should be correct, but it doesn't work:

net.sf.hibernate.QueryException: undefined alias: {fn

Should I use a SQL based query instead of HQL?. Is there any other way to obtain the month and year of a date field?.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 28, 2004 3:51 pm 
Senior
Senior

Joined: Sun Jan 04, 2004 2:46 pm
Posts: 147
If you're using a very recent version of hibernate you can create a custom dialect and add these functions to the permissable list so hibernate will just pass them straight through to the db. Then just write HQL with the functions in ( think this only works for the select clause ).


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 29, 2004 1:55 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
and if that doesn't work try to use createSQLQuery (which unfortunately at this moment only allows you to fetch mapped objects and not scalar/projected values)

_________________
Max
Don't forget to rate


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.