========================================================
I have a problem, it is like following:
hbm.xml is as following:
------------------------
..
..
.
..
Code:
<composite-id name="id" class="com.....model.AlarmViolationLogId">
<key-property name="alarmid" type="integer">
<column name="ALARMID" />
</key-property>
<key-property name="readingdatetime" type="timestamp">
<column name="READINGDATETIME" length="26" />
</key-property>
</composite-id>
.
.
.
-----------------------
pojo file is like following:
-----------------------------
Id pojo
Code:
public class AlarmViolationLogId implements java.io.Serializable {
// Fields
private Integer alarmid;
private Date readingdatetime;
......
}
POJO:
Code:
public class AlarmViolationLog implements java.io.Serializable {
// Fields
private AlarmViolationLogId id;
private double readingval;
private double alarmval;
private short violationcount;
private double kwreadingval;
private Date dateadded;
private Integer gatewayid;
...
}
----------------------------
then the HQL is like following:
----------------------------
Code:
String query="select ....from ....where .....and alarmviolationlog.id.readingdatetime >= ? and alarmviolationlog.id.readingdatetime <= ? and site.siteid = ?";
arg0 is Object[3];
String dss="2005-08-23 22:55:00.000000000";
java.util.Date dates=new Date(Timestamp.valueOf(dss).getTime());
String dsg="2005-08-23 23:55:00.000000000";
java.util.Date dateg=new Date(Timestamp.valueOf(dsg).getTime());
arg0[0]=dates;
arg0[1]=dateg;
arg0[2]=new Integer(1580);
then
return getHibernateTemplate().find(query,arg0);
return an empty list,
If I remove the ---alarmviolationlog.id.readingdatetime <= ? and alarmviolationlog.id.readingdatetime <= ? --- from the where clause, it works fine, but this i s what I want, also it works fine if I use (less than compare operator <), I believe this is a bug of how to transfer the date to a string based on the DB dialect.
===========================
I am using Spring/Hibernate/DB2/Eclipse,
If I run the query directly on DB2, return 8 results, the only difference is that I am using '2005-08-23-22.55.00.000000000' and '2005-08-23-23.55.00.000000000', and it works fine. I use "'2005-08-23 22:55:00.000000000'", then the DB2 will complain.
{........s.siteid=1580 and readingdatetime < '2005-08-23-22:55:00' and readingdatetime < '2005-08-23-23:55:00'" | more
SQL0180N The syntax of the string representation of a datetime value is
incorrect. SQLSTATE=22007
}
Also I noticed the log output from Eclipse is like :
DEBUG main org.hibernate.type.TimestampType - binding '2005-08-23 22:55:00' to parameter: 1
DEBUG main org.hibernate.type.TimestampType - binding '2005-08-23 23:55:00' to parameter: 2
======================================================
Really need help on how to compare the timestamp type in my situation?
Any suggestion will be appreciated?
Thanks