I would like to persist an instance of my class into objectdb.
@Entity
public class MyClazz {
@Column(nullable = false)
DateTime date;
}
With hibernate I just need to annotate the field with an additional annotation.
@Type(type = "org.jadira.usertype.dateandtime.joda.PersistentDateTime")
But since I want to use objectdb I can't use these annotation, so I get an exception ("Attempt to store an instance of a non persistable type org.joda.time.DateTime")
The problem is that objectdb disables the "support" for serializable types. (see here) I'm pretty sure that they do this for a good reason so want to keep it this way.
As a workaround for now I use a pre and post hook.
@Column(nullable = false)
private Date date = new Date();
@Transient
private DateTime dateTime;
@PrePersist
private void persist() {
date = dateTime.toDate();
}
@PostLoad
private void load() {
dateTime = new DateTime(date.getTime());
}
My question: is there another way? I would like to get rid of the additional date field.
I'm pretty sure that they do this for a good reason so want to keep it this way.
Yea. When you save a serialized object in a database, your queries won't be able to perform any tests on the object; e.g. test whether one date is later than another one. In addition, you are making your application vulnerable to the problem of incompatible serial versions. (That's probably not an issue in this specific example, but the issue comes up repeatedly in SO questions ...)
My question: is there another way? I would like to get rid of the additional date field.
Unfortunately, I don't think there is.