EBean(4.5.x)是否支持映射Java 8的时间类型,例如OffsetDateTime

时间:2016-01-22 02:11:47

标签: java playframework java-8 ebean

有一个closed ticket表明Ebean 4.4.1及以后版本支持Java 8的时间类,例如OffsetDateTime。但是,我找不到任何显示使用这些类的Ebean文档。

对于如下所示的AppUser类,是否完全支持使用OffsetDateTime而不是java.sql.Timestamp

@Entity
public class AppUser extends Model {

    @Id
    private Long id;
    private String username;
    private OffsetDateTime lastSeen;

    // Constructor, getters and setters
}

1 个答案:

答案 0 :(得分:6)

这些新类型没有文档,但代码非常简单明了:

https://github.com/ebean-orm/avaje-ebeanorm/blob/master/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeOffsetDateTime.java

正如您在代码中看到的那样,OffsetDateTime被映射到java.sql.Timestamp。以下是Ebean如何将java.time类型映射到java.sql.Types的(可能)完整表格:

| Java 8 java.time.*               | java.sql.Types |
|:---------------------------------|:---------------|
| DayOfWeek                        | INTEGER        |
| Duration                         | BIGINT         |
| Duration (with nanos precision)  | DECIMAL        |
| Instant                          | TIMESTAMP      |
| LocalDate                        | DATE           |
| LocalDateTime                    | TIMESTAMP      |
| LocalTime                        | TIME           |
| LocalTime (with nanos precision) | BIGINT         |
| Month                            | INTEGER        |
| MonthDay                         | DATE           |
| OffsetDateTime                   | TIMESTAMP      |
| OffsetTime                       | VARCHAR        |
| Year                             | INTEGER        |
| YearMonth                        | DATE           |
| ZoneId                           | VARCHAR        |
| ZoneOffset                       | VARCHAR        |
| ZonedDateTime                    | TIMESTAMP      |