有一个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
}
答案 0 :(得分:6)
这些新类型没有文档,但代码非常简单明了:
正如您在代码中看到的那样,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 |