Java exception when using @CreationTimestamp or @UpdateTimestamp annotation in Embeddable


#1

When I use the @CreationTimestamp or @UpdateTimestamp in an embeddable java throws exception:

javax.persistence.PersistenceException: Unable to build Hibernate SessionFactory

…which is caused by:
Caused by: org.hibernate.cfg.NotYetImplementedException: Still need to wire in composite in-memory value generation

I’ve tried with both Hibernate ORM 5.1, 5.2, and 5.3 with the same results. Does anybody know if this is a reported bug or are those annotations not supported?


#2

Make sure you must be used over Date or Calendar object

you may be used for the Long object.

if you use

@CreareTimestame

Date createTime

@UpdateTimestamp

Date updateTime


#3

If you can replicate it with this test case templates, you should open a Jira issue.


#4

I’m using the Calendar object as shown below.

@Column(insertable = false, updatable = false, nullable = false)
@CreationTimestamp
@Temporal(TemporalType.TIMESTAMP)
private java.util.Calendar createdOn;

@Column(insertable = false, updatable = false, nullable = false)
@UpdateTimestamp
@Temporal(TemporalType.TIMESTAMP)
private java.util.Calendar updatedOn;

#5

You can use the @CreationTimestamp and @UpdateTimestamp with the following attribute types:
java.time.LocalDate (since Hibernate 5.2.3)
java.time.LocalDateTime (since Hibernate 5.2.3)
java.util.Date
java.util.Calendar
java.sql.Date
java.sql.Time
java.sql.Timestamp

like:
@Entity
public class MyEntity {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = “id”, updatable = false, nullable = false)
private Long id;

@Column
private String value;

@Column
@CreationTimestamp
private LocalDateTime createDateTime;

@Column
@UpdateTimestamp
private LocalDateTime updateDateTime;

…

}


#6

It seems to work if you do not embed it. But in my case the @CreationTimestamp and @UpdateTimestamp is in an embeddable and this is where I get the java exception mentioned. Have you tried it recently in an embedded and has it worked for you?


#7

Sound like a bug. You should add a Jira issue for this and provide a replicating test case.