I would like to get all records from a MySQL date field with the Hibernate Criteria API. Basically I would like the query to select all rows from the date to a predefined month (e.g January). This is my MySql query that executes successfully
select * from user u where month(u.birth_date) = 1; //1 for January
I want to convert this MySql Query to hibernate Criteria, like
criteria.add(Restrictions.eq("month(birth_date)", month));
but it's give error.
DB DataType for birth_date is Timestamp.
Thanks in advance.
You have to write your own expression. Then use that expression with criteria. You can see this link on how to create expression. How to query on a month for a date with Hibernate criteria