-->
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: using built in functions from mysql
PostPosted: Sat Feb 25, 2006 8:58 pm 
Newbie

Joined: Mon Feb 20, 2006 1:21 pm
Posts: 12
hello hibernate users

a have a very simple schema set up with hibernate working fine so far. i use criteria to search for a particular rows

now i need to use a built in function from mysql. the query is like so:

select dayofmonth(list_date)
from top_ten_title
where list_date between '2004-7-1' and '2004-8-1';

can i use criteria for this also, or what is the suggested way?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 27, 2006 12:37 am 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
You can use Session.createSQLQuery() for that. Or you can use HQL with the day() HQL function (this is recommended, because it's portable). If you want to use Criteria, you have two options: either get the day ouf of the java.util.Date object in the normal way, after the critieria is executed; or map a new dayOfMonth member of your object, specifically for this query.

To do this last one, you'd have to add the new member to your interface/impl in the normal way, and define your mapping as
Code:
  <property name="dayOfMonth" formula="dayofmonth(list_date)"/>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 27, 2006 12:34 pm 
Newbie

Joined: Mon Feb 20, 2006 1:21 pm
Posts: 12
thank you i will give it a shot. i want to know what the most common practice or best solution is, i dont have to use criteria at all


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.