Search code examples
timeebean

How to set type "time" with a model and ebean?


I'd like to only use the time for my model, to define when in the day the event is going to occur, but the only way I found was to do this:

@Temporal(TemporalType.TIME)
public Date end;

But I'd like to have in my database, a type TIME which is exactly what I'm looking for.

How can I do that?


Solution

  • You can use java.sql.Time, but be careful - it has other definition than MySQL TIME column type - it operates only in range 00:00:00 - 23:59:59 (although MySQL allows you to store intervals -/+ 838 hours)

    model:

    public Time end;
    

    set with:

    event.end = Time.valueOf("12:15:00");
    

    Anyway maybe it's safer to store the time/interval as a string or integer (of minutes)?