I am writing an application using JPA with GlassFish 3.1.2.2 and EclipseLink 2.3.2. I am using Oracle DB 11g and trying to save the date and time with the time zone using the field type TIMESTAMPTZ.
With my setup, I can save the date and time with the time zone in the database. (Update. In fact, when you look at the actual SQL call, it only passes the date and time. Oracle should add the time zone when saving to the database).
However, when returning data, I get the following exception:
Exception [EclipseLink-3002] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.ConversionException Exception Description: Object [ oracle.sql.TIMESTAMPTZ@12cbe3f ], from class [class oracle.sql.TIMESTAMPTZ] , from the mapping [org.eclipse.persistence.mappings.DirectToFieldMapping [startDateTime β APPT_EVENT.START_DATE_TIME]] ββto the handle [RelationalDescriptor (com.ntst.caremanager.server.entities.ApptEvent β [DatabaseTable (APPT_EVENT)] be converted to [class java.util.Date].
Has anyone ever come across this before? This creates my startDateTime field in my entity class:
@Column(name = "START_DATE_TIME") @Temporal(TemporalType.TIMESTAMP) private Date startDateTime;
START_DATE_TIME is defined in the database by the following DDL:
"START_DATE_TIME" TIMESTAMP (6) WITH TIME ZONE
I read on the eclipelink wiki here that EclipseLink natively supports oracle TIMESTAMPTZ without the need for conversion. I also tried using the Calendar type instead of the Date in the entity class.
Update: Also tried this
@Convert("timestamptz") @TypeConverter(name="timestamptz", dataType=TIMESTAMPTZ.class) @Column(name = "START_DATE_TIME") @Temporal(TemporalType.TIMESTAMP) private Date startDateTime;
Bad luck. Oddly enough, when adding converters, saving the database no longer works. I get this error when trying to save a value.
Exception [EclipseLink-3002] (Eclipse Persistence Services - 2.3.3.v20120629-r11760): org.eclipse.persistence.exceptions.ConversionException Exception Description: object [12/4/12 7:00 AM], class [class java. util.Date], from the mapping [org.eclipse.persistence.mappings.DirectToFieldMapping [startDateTime β APPT_EVENT.START_DATE_TIME]] ββto the handle [RelationalDescriptor (com.ntst.caremanager.server.entities.ApptEvent β [DatabaseTable) APP__ cannot be converted to [class oracle.sql.TIMESTAMPTZ].
I am still getting the same error when trying to get the value. I also tried updating Glassfish to EclipseLink 2.3.3 and got the same error.
This is my persistence file:
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"> <persistence-unit name="CM-warPU" transaction-type="JTA"> <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> <jta-data-source>CMDEV</jta-data-source> <exclude-unlisted-classes>false</exclude-unlisted-classes> <properties> <property name="eclipselink.logging.level" value="FINE"/> <property name="eclipselink.logging.parameters" value="true"/> <property name="eclipselink.target-server" value="SunAS9"/> </properties>
Has anyone seen this problem before, or seen any mistake I might have made?
Thanks!