Is there a way to set a date/time field to the current time so that selecting
entities ordered by this field will retain the real construction (not
necessarily insertion) order?
So ideally it would be a function that creates Timestamps and is guaranteed to
return a larger Timestamp if you call it right after creating a Timestamp. But
I can't find such a TimeStamp constructor. I know something like that must
exist internally for version columns in OpenJPA, but my AbstractEntity class
already has a version field of type Long which I don't really want to change.
What I tried was this:
@Temporal(TemporalType.TIMESTAMP)
@Column(nullable = false)
private Date creationTime;
When I do creationTime = new Date() in my constructor I get this when creating
and persisting 10 entities:
2011-05-03 11:22:53.8700000
2011-05-03 11:22:53.8700000
2011-05-03 11:22:53.8800000
2011-05-03 11:22:53.8800000
2011-05-03 11:22:53.8800000
2011-05-03 11:22:53.8900000
2011-05-03 11:22:53.8900000
2011-05-03 11:22:53.9000000
2011-05-03 11:22:53.9000000
2011-05-03 11:22:53.9100000
This is not really accurate enough to guarantee the order.
Regards,
Henno Vermeulen
Huize Molenaar