This is most likely an old problem fixed in Hibernate 5.2.
To prove this, simply run LocalDateTimeWithTemporalTimeTest from the Hibernate master branch.
The object looks like this:
@Entity(name = "DateEvent") public static class DateEvent { @Id @GeneratedValue private Long id; @Column(name = "`timestamp`") private LocalDateTime timestamp; public DateEvent() { } public DateEvent(LocalDateTime timestamp) { this.timestamp = timestamp; } public Long getId() { return id; } public LocalDateTime getTimestamp() { return timestamp; } }
The table below is as follows:
create table DateEvent ( id bigint not null, "timestamp" timestamp, primary key (id) )
And both save and choose the job as expected:
doInJPA( this::entityManagerFactory, entityManager -> { DateEvent dateEvent = new DateEvent( LocalDateTime.now() ); dateEvent.id = 1L; entityManager.persist( dateEvent ); } ); doInJPA( this::entityManagerFactory, entityManager -> { DateEvent dateEvent = entityManager.find( DateEvent.class, 1L ); assertNotNull(dateEvent.getTimestamp()); } );
source share