Hi, under PostGresql, Im using PersistentDuration for the mapping between the sql type interval & duration but it doesnt work. An other user found the same issue & come with his own class:
public void nullSafeSet(PreparedStatement statement, Object value, int index)
throws HibernateException, SQLException {
if (value == null) {
statement.setNull(index, Types.OTHER);
} else {
Long interval = ((Long) value).longValue();
Long hours = interval / 3600;
Long minutes = (interval - (hours * 3600)) / 60;
Long secondes = interval - (hours * 3600) - minutes * 60;
statement.setString(index, "'"+ hours +":"
+ intervalFormat.format(minutes) + ":"
+ intervalFormat.format(secondes)+"'");
}
}
But it doesnt work with the real format because it supposes the interval pattern is only "hh:mm:ss". That is not the case: see
Here some few real examples i need to parse from the database:
- 1 day 00:29:42
- 00:29:42
- 1 week 00:29:42
- 1 week 2 days 00:29:42
- 1 month 1 week 2 days 00:29:42
- 1 year 00:29:42
- 1 decade 00:29:42
http://www.postgresql.org/docs/8.0/interactive/datatype-datetime.html
Have you a clean solution ? Thanks in advance Regards