Skip to content

Oracle Interval Support

Philippe Marschall edited this page Jan 5, 2019 · 5 revisions

We also support mapping Oracle INTERVAL to the following types

Oracle SQL Java SE 8
INTERVAL YEAR TO MONTH Period
INTERVAL DAY TO SECOND Duration

We believe they are a close semantic match. The Oracle data types documentation mentions

Oracle performs all timestamp arithmetic in UTC time. For TIMESTAMP WITH LOCAL TIME ZONE, Oracle converts the datetime value from the database time zone to UTC and converts back to the database time zone after performing the arithmetic. For TIMESTAMP WITH TIME ZONE, the datetime value is always in UTC, so no conversion is necessary.

This matches the Duration semantics where no daylight savings time exists.

One important difference is that in Oracle date arithmetic with an valid result would lead to an error.

When interval calculations return a datetime value, the result must be an actual datetime value or the database returns an error.

Where as in Java 8 methods like plusMonths would automatically correct invalid results

For example, 2007-03-31 plus one month would result in the invalid date 2007-04-31. Instead of returning an invalid result, the last valid day of the month, 2007-04-30, is selected instead.

EclipseLink

threeten-jpa-oracle-eclipselink contains JPA attribute converters which need to be listed in persistence.xml

<persistence-unit>
    …
    <class>com.github.marschall.threeten.jpa.oracle.OraclePeriodConverter</class>
    <class>com.github.marschall.threeten.jpa.oracle.OracleDurationConverter</class>
    …
</persistence-unit>

Hibernate

threeten-jpa-oracle-hibernate contains Hibernate user types which need to be used using @Type

@Entity
public class SampleEntity {

  @Column
  @Type(type = OracleDurationType.NAME)
  private Duration duration;

  @Column
  @Type(type = OraclePeriodType.NAME)
  private Period period;

}

Class Loading

Note the Oracle driver module has to be visible to the deployment (e.g Class Loading in WildFly).

Clone this wiki locally