2

I'm trying to setup hibernate in my new project and I have this problem. I'm using oracle database.

In some tables I have more than one column that are timestamp.

Hibernate maps this columns as Serializable.

I tried to change manually to LocalTime type but the project won't even run. I change both on Availability.java and Availability.hbm.xml.

Is it supposed to be Serializable? I would like to use LocalTime instead. Is there a way to do this?

I found this: How to map oracle timestamp to appropriate java type in hibernate?. But it was 5 years ago and it seems like a complicated solution..

public class Availability  implements java.io.Serializable {
    private int id;
    private Teacher teacher;
    private byte month;
    private short year;
    private Serializable initialhour;
    private Serializable endhour;
    private String weekday;
    public void setInitialhour(Serializable initialhour) {
        this.initialhour = initialhour;
    }
    public Serializable getEndhour() {
        return this.endhour;
    }
}
Community
  • 1
  • 1
Duarte Mendes
  • 161
  • 3
  • 12

3 Answers3

2

You can just use:

  private Timestamp initialhour;

If you want to can add annotation, but it should work just fine without it:

 @Temporal(TemporalType.TIMESTAMP)
 private Timestamp initialhour;

If you want to use java 8 DateTime you can use the @Type annotation, something like that:

@Type(type = "org.jadira.usertype.dateandtime.joda.PersistentDateTime")
private DateTime initialhour;
Dodo
  • 36
  • 2
0

Try to add hibernate-java8 to your project. The issue is that LocalTime is a Java8 class which Hibernate does not support by default.

Sergii Bishyr
  • 8,331
  • 6
  • 40
  • 69
0

The same happened to me, also with "interval to day" datatype, the easiest way I found to manually solve this was replacing "Serializable" for "Timestamp", not so clean but works for me.

MikeOx
  • 167
  • 1
  • 1
  • 16