-->
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: Problem with createCriteria, Restrictions and TimeStamp
PostPosted: Wed Sep 30, 2009 6:01 am 
Newbie

Joined: Wed Sep 30, 2009 5:08 am
Posts: 2
The problem: I want to get all students who born in May.

This is my sql:
Code:
Select * from student where Month(birthday) = 5 (i used mysql)

And session.createQuery:
Code:
String sql = "From student where birthday like :month";
    Query query = session.createQuery(sql);
    query.setString("month", "%-05-%");
    query.list();
   

But how can i implement by using session.createCriteria?
when i add this statement: criteria.add(Restrictions.like("birthday", "%-05-%")); an error appear because birthday have data type is TimeStamp.


Top
 Profile  
 
 Post subject: Re: Problem with createCriteria, Restrictions and TimeStamp
PostPosted: Wed Sep 30, 2009 2:30 pm 
Regular
Regular

Joined: Mon Jan 05, 2009 6:42 pm
Posts: 99
Location: IL
Have you tried this:
String sql = "From student where birthday between :firstDayOfMonth and :lastDayOfMonth";

also why is "birthday" a timestamp? it can be if you want to capture the exact time of course. But is that what you are doing?
-Srilatha.


Top
 Profile  
 
 Post subject: Re: Problem with createCriteria, Restrictions and TimeStamp
PostPosted: Wed Sep 30, 2009 9:51 pm 
Newbie

Joined: Wed Sep 30, 2009 5:08 am
Posts: 2
Srilatha, thanks for your reply.
But with your query, you loss year's field. How can i got birthday of 05/09/2004 and 05/12/2009 .... if i use between?
Anyone can help me.


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.