-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Time and Date Questions
PostPosted: Sat Dec 01, 2007 8:40 am 
Newbie

Joined: Fri May 25, 2007 4:37 am
Posts: 13
Location: Germany
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?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.