-->
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: MySQL DATE_SUB() function in Hibernate
PostPosted: Mon Aug 11, 2008 11:27 am 
Newbie

Joined: Thu Apr 19, 2007 12:47 am
Posts: 6
Hi,

I am using hibernate with MySQL.

I have written query in MySQL which will fetch records of last 30 days. For that i have written query using DATE_SUB() function of MySQL.

But, its not working in hibernate's query. So, how i can implement DATE_SUB() function in hibernate ?

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 12, 2008 6:41 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

could you be more specific about your usecase? Are you trying to execute a native query or are you trying to use HQL. In the former case you should be able to use database specific functions in the latter case not.

Maybe you could post the code you are trying to execute, together with your configuration files and stacktraces (if any) when executing the code.

--Hardy


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 12, 2008 11:26 am 
Newbie

Joined: Thu Apr 19, 2007 12:47 am
Posts: 6
Thanks for reply.
I am using HQL.
I have implemented below code :

String searchQuery = "..........
and date_sub_interval(curdate(), 28, DAY ) < b_date and
........";

(where b_date is table filed).

class Dialect extends MySQLInnoDBDialect {

public Dialect() {
super();
registerFunction("date_sub_interval", new SQLFunctionTemplate(
Hibernate.DATE, "date_sub(?1, INTERVAL ?2 ?3)"));
}

}

In above code i am getting error. I am not sure whether above code is correct or not.

Error says:
'DAY' field not found.

I haven't done any other configurations. I have implemented hibernate code using EntityManager and annotations based api.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 13, 2008 6:20 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

what data type is 'DAY' in your query. wouldn't you just pass it as string? Maybe you have more luck asking this question on the main Hibernate forum.

--Hardy


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.