Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does EBean (4.5.x) support mapping Java 8's time types such as OffsetDateTime

There is a closed ticket suggesting that Ebean 4.4.1 and onwards supports Java 8's time classes, such as OffsetDateTime. However, I can't find any Ebean documentation showing the use these classes.

For a class such as AppUser shown below, is it fully supported to use OffsetDateTime instead of java.sql.Timestamp?

@Entity
public class AppUser extends Model {

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

    // Constructor, getters and setters
}
like image 309
Kevin Avatar asked Apr 28 '26 09:04

Kevin


1 Answers

There is no docs for these new types, but the code is pretty simple and straightforward:

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

As you can see at the code, OffsetDateTime is mapped to a java.sql.Timestamp. Here is a (likely) complete table of how Ebean maps java.time types to 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      |
like image 197
marcospereira Avatar answered Apr 30 '26 23:04

marcospereira