How to Introduce Oracle Interval in Java

I am using Java 7 with hibernate 4.

Want to use the oracle Data Type Interval ( http://psoug.org/definition/INTERVAL.htm ) to represent an interval of a certain number of days.

Learning what type of Java to use to map this Oracle interval object.

I would like to use standard Java objects, not any oracle.sql objects. * as indicated in this document http://docs.oracle.com/cd/B28359_01/java.111/b31224/datacc.htm .

Here is the table I play in:


CREATE TABLE "MyTest" ( "ID" NUMBER(14,0) NOT NULL "DELIVERY_PERIOD" INTERVAL DAY (3) TO SECOND (6), CONSTRAINT "MYTEST_PK" PRIMARY KEY ("ID")); 

Edit

Since then i tried with

 @Temporal(TemporalType.TIME) private java.util.Date deliveryPeriod; 

Getting error:

 Caused by: java.sql.SQLException: Invalid column type: getTime not implemented for class oracle.jdbc.driver.T4CIntervaldsAccessor 

Edit 2

http://docs.oracle.com/cd/B12037_01/java.101/b10983/datamap.htm

I know that matching it with Java String will work, but I would like it to be some kind of date object, so I don't need to parse it myself.

http://objectmix.com/jdbc-java/41781-oracle10g-oracle-sql-interval-type.html

I would also like to avoid using specific oracle data types like oracle.sql.INTERVALS

+6
source share
2 answers

Check the SO answer :

  • You can define a custom Interval Hibernate type
  • Then your objects will just use Integer:

     @TypeDef(name="interval", typeClass = Interval.class) @Type(type = "interval") private Integer interval; 
  • Internal UserType is a Java Integer to SQL INTERVAL adapter.

+3
source

If mapping to String works, you can either

  • (JPA 2.1) write converter or
  • (JPA <2.1) Hibernate Custom Type Record

to convert between String and Interval.

You can write POJO yourself for Interval or use JODA Time Duration

+1
source

Source: https://habr.com/ru/post/973631/


All Articles