I have an application where a user can specify when a playlist should be played.
Example: Playlist "X-MAS" should be played from 1st Dec. to 26th Dec. Every day from 09:00 AM til 06:00 PM.
Therefore I created this mapping:
Code:
@Column(name = "rps_timestart", nullable = true)
private Time timestart = null;
@Column(name = "rps_timeend", nullable = true)
private Time timeend = null;
@Column(name = "rps_datestart", nullable = true)
private Date datestart = null;
@Column(name = "rps_dateend", nullable = true)
private Date dateend = null;
And my Criteria Query looks like this:
Code:
Date date = new Date();
Time time = new Time(date.getTime());
// ...
.add(Expression.or(
Expression.and(
Expression.isNull("timestart"),
Expression.isNull("timeend")
),
Expression.and(
Expression.le("timestart", time),
Expression.ge("timeend", time)
)
)
)
.add(Expression.or(
Expression.and(
Expression.isNull("datestart"),
Expression.isNull("dateend")
),
Expression.and(
Expression.le("datestart", date),
Expression.ge("dateend", date)
)
)
)
So if a column is set to null, it is ignored and everything works perfectly, unless someone wants to start a playlist at 00:00 AM. I then have an entry '00:00:00' in the database. When Hibernate tries to read this, an exception is thrown, because java.sql.Time cannot be used with 00:00:00.
I cannot find any help on this. Can someone tell me, how to handle the Time values?