0

我在用着:

Eclipselink 2.5.0
HSQLDB 2.3
JPA 2.1
Spring 4.0.5

我有这个实体:

@Entity
public class MyEntity {

    ...

    @Temporal(TemporalType.DATE)
    @Convert(converter = MyLocalDateTimeConverter.class)
    private LocalDate date;

}

当 HSQLDB/Eclipselink 生成 DDL 时,它生成 dabase 字段为:

TIMESTAMP

当我访问(通过选择)这个实体时,我的转换器得到 ajava.sql.Timestamp而不是java.sql.Date并将值转换为 aLocalDateTime而不是LocalDate

如何强制将字段生成为:

DATE // respecting the Temporal definition
4

1 回答 1

-1

The reason you are getting a java.sql.TimeStamp is very easy, you have not only year, month and day in the DB, but also hour, minute and second perhaps.

The only difference between java.sql.Date and java.sql.Timestamp is Timestamp carries more information like hour,..

..., which means, it is correct for you to get a java.sql.Timestamp.

PS: java.sql.Date and java.sql.Timestamp are both wrapper of java.util.Date..

于 2014-06-03T15:35:13.780 回答