2

I'm having some problems with a simple query I'm doing. I have a postgresql database, with a time wihout zone column.

I cannot change the type of this column. Also, I have to use criterias, so don't tell me to change this. However, if there is a better solution for the future instead of using the time type I'm curious about it.

This column is mapped to a java.util.Date attribute. This could be changed to Time or whatever. What I'm doing is adding this :

Time someTime = someDate.getTime();
criteria.add(Restrictions.eq(propertyName, someTime)));

This criteria doesn't return anything, when it should. What is done is the following: The user puts some string time, that is parsed to Date, being that 1970-1-1 and the time. This time is then added to the criteria. Also, the time in the database I'm using as example, is the same Date (1970-1-1, etc) that the one that is created when parsing the user data.

I have tried to search for some documentation on how criterias are used against time without timezone but haven't found anything.

Suggestions why this is failing?

UPDATE:The problem has been solved using the library JodaTime. But I still don't understand why was failing...

dgmora
  • 1,239
  • 11
  • 27
  • Are the two times the exact same instant? As in, they return the same value for [`Date#getDate()`](http://docs.oracle.com/javase/6/docs/api/java/util/Date.html#getTime())? – millimoose Dec 28 '11 at 17:26
  • Yes, the fastime and also the cDate content is exactly the same. I'm adding this restriction to the criteria with Restrictions.eq, in case it matters. – dgmora Dec 30 '11 at 12:49
  • I think your problem is you are comparing java.util.Date with java.sql.Date – Rajesh Pantula Jan 11 '12 at 17:33

0 Answers0