Duarte Mendes
Duarte Mendes

Reputation: 161

Hibernate maps Timestamp as Serializable

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;
    }
}

Upvotes: 2

Views: 976

Answers (3)

MikeOx
MikeOx

Reputation: 177

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.

Upvotes: 0

Dodo
Dodo

Reputation: 36

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;

Upvotes: 2

Sergii Bishyr
Sergii Bishyr

Reputation: 8651

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

Upvotes: 0

Related Questions