Hi all,
Hibernate version:
3.0
Name and version of the database you are using:
SQL Server 2000
I created the following mapping :
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.farbeyond.server.dao.entities.BranchImpl"
table="Branches">
<id name="rowId" column="rowId" type="int">
<generator class="native">
</generator>
</id>
<property name="rowId"
type="int"
update="false"
insert="false"
column="rowId"/>
<property name="branchId"
type="int" update="true"
insert="true"
column="branchId"/>
<property name="branchName"
type="java.lang.String"
update="true"
insert="true"
column="branchName"/>
<property name="dateTimeCreated"
type="date"
update="true"
insert="true"
column="dateTimeCreated"/>
</class>
</hibernate-mapping>
I insert record using the following query :
Code:
INSERT INTO Branches (branchId,branchName,dateTimeCreated)
VALUES (1,'Branch 1','2005-01-03 14:12:41')
Then I execute Hibernate Criteria :
Code:
...
Calendar cal = Calendar.getInstance();
cal.set(2005,Calendar.JANUARY,3);
criteria.add(Restrictions.eq("dateTimeCreated",cal.getTime()));
List list = getHibernateTemplate().findByCriteria(criteria,0,100)
System.out.println("size : " + list.size()); //returns no record.
...
The above criteria returns no record.
I also tried to change the calendar to:
Code:
cal.set(2005,Calendar.JANUARY,3,14,12,41);
the result is the same, no record.
But if I insert record using the following query :
Code:
INSERT INTO Branches (branchId,branchName,dateTimeCreated)
VALUES (1,'Branch 1','2005-01-03')
and execute the same Hibernate Criteria using calendar with or without the time parameters, it returns the desired records.
I run the same test under PostgreSQL without problems. I guess this is due to the SQL Server date data type that combines date and time at once instead of separate date and time data type as provided by PostgreSQL.
I have tables that might be queried against its datetime field with or without its time, so I need to find one-fits-all solution on this problem. Worse thing is I also need the solution to be portable accross SQLServer, PostgreSQL and MySQL databases.
Any help would be greatly appreciated.
Best Regards,
Setya