I'm using Java 7 with hibernate 4.
Want to use oracle Interval data type (http://psoug.org/definition/INTERVAL.htm) to represent a interval of a certain number of days.
Wondering what Java Type to use to map this Oracle Interval Object.
I would like to use standard Java objects and not any oracle.sql.* objects as mentioned in this document http://docs.oracle.com/cd/B28359_01/java.111/b31224/datacc.htm.
Here's the table I'm playing with:
CREATE TABLE "MyTest" (
"ID" NUMBER(14,0) NOT NULL
"DELIVERY_PERIOD" INTERVAL DAY (3) TO SECOND (6),
CONSTRAINT "MYTEST_PK" PRIMARY KEY ("ID"));
Edit
I've since tried with
@Temporal(TemporalType.TIME)
private java.util.Date deliveryPeriod;
Getting the 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 mapping it to Java String would work, but I would like to get it is some sort of date object so I don't have to parse it myself.
http://objectmix.com/jdbc-java/41781-oracle10g-oracle-sql-interval-type.html
I would also like to avoid using oracle specific data types such as oracle.sql.INTERVALS
Check this SO answer:
Then your Entities will simply use Integer:
@TypeDef(name="interval", typeClass = Interval.class)
@Type(type = "interval")
private Integer interval;
The Internal UserType is the Java Integer to SQL INTERVAL adapter.
If mapping to String works, then you can either
to convert between String to Interval class.
You can write a POJO yourself for Interval, or make use of JODA Time's Duration
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With