这确实是一个错误。我在下面的测试中复制了它。我会为它打开一个错误报告。
如果我使用LocalDate
:
@Entity(name = "LocalDateEvent")
public class LocalDateEvent {
@Id
private Long id;
@NotNull
@Column(name = "START_DATE", nullable = false)
private LocalDate startDate;
}
并运行此测试:
doInJPA(entityManager -> {
LocalDateEvent event = new LocalDateEvent();
event.id = 1L;
event.startDate = LocalDate.of(1, 1, 1);
entityManager.persist(event);
});
doInJPA(entityManager -> {
LocalDateEvent event = entityManager.find(LocalDateEvent.class, 1L);
assertEquals(LocalDate.of(1, 1, 1), event.startDate);
});
我得到:
java.lang.AssertionError: expected:<0001-01-01> but was:<0000-12-29>
Jira 问题就在这里。
它不适用于以下OffsetDateTime
任何一个:
@Entity(name = "OffsetDateTimeEvent")
public static class OffsetDateTimeEvent {
@Id
private Long id;
@NotNull
@Column(name = "START_DATE", nullable = false)
private OffsetDateTime startDate;
}
并运行此测试:
doInJPA(entityManager -> {
OffsetDateTimeEvent event = new OffsetDateTimeEvent();
event.id = 1L;
event.startDate = OffsetDateTime.of(1, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC);
entityManager.persist(event);
});
doInJPA(entityManager -> {
OffsetDateTimeEvent event = entityManager.find(OffsetDateTimeEvent.class, 1L);
assertEquals(OffsetDateTime.of(1, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC), event.startDate);
});
抛出:
java.lang.AssertionError: expected:<0001-01-01T00:00Z> but was:<0001-01-01T01:34:52+01:34:52>
Jira 问题在这里。