TimeZone Error with EclipseLink and Oracle DB

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!

+4
source share
3 answers

I was able to understand this, and in fact it was because of an omission on my part. I needed to add the ojdbc6.jar file to domainfish domains \ domain1 \ lib \ ext \ so that EclipseLink could find the type oracle.sql.timestamptz.

What is it. After that, I can get and save the time zone data in the Oracle database using:

 @Column(name = "START_DATE_TIME") @Temporal(TemporalType.TIMESTAMP) private Calendar startDateTime; 

You do not need to use @TypeConverter or @Converter, as EclipseLink will automatically convert it to this version. You also need to use Calendar, not Date, so you can get information about TimeZone.

I leave it to anyone who might run into this.

+1
source

You need to specify a converter

 @Convert("timestamptz") @TypeConverter(name="timestamptz", dataType=TIMESTAMPTZ.class) @Column(name = "START_DATE_TIME") @Temporal(TemporalType.TIMESTAMP) private Date startDateTime; 

You also need to configure the server platform so that EclipseLink can connect a JDBC connection for the correct conversion. This can be done in the persistence.xml file.

 <property name="eclipselink.target-server" value="WebLogic"/> 
+1
source

After you have tried most of the solutions mentioned here:

  • Adding ojdbc6.jar to the classpath.
  • With and without @TypeConverter and @Converter.
  • Change the property of the object from and to java.util.Date and java.util.Calendar.
  • Install eclipselink.target-server in weblogic.

... the following error remained:

Exception [EclipseLink-3002] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.ConversionException Exception Description: object [ oracle.sql.TIMESTAMPTZ@12cbe3f ], class [class oracle.sql.TIMESTAMPTZ], from displaying [Org.eclipse.persistence.mappings.DirectToFieldMapping [...]] with the handle [RelationalDescriptor (com.ntst.caremanager.server.entities.ApptEvent β†’ [DatabaseTable (APPT_EVENT)])], could not be converted to [class java.util.Date].

I finally got the job done (without @converter and with java.util.Calendar in my essence) when I changed the eclipselink.target database from "Oracle" to "Oracle11".

+1
source

All Articles