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;
}
}
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;
Try to addhibernate-java8 to your project. The issue is that LocalTime
is a Java8 class which Hibernate
does not support by default.
同样的事情发生在我身上,也是“间隔到一天”数据类型,我发现手动解决这个问题的最简单方法是将“可序列化”替换为“时间戳”,不太干净但对我有用。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.