Bug 369617 - ClassCastException TIMESTAMPTZWrapper cannot be cast for Oracle TIMESTAMP WITH TIME ZONE columns
Summary: ClassCastException TIMESTAMPTZWrapper cannot be cast for Oracle TIMESTAMP WIT...
Status: NEW
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P2 major with 1 vote (vote)
Target Milestone: ---   Edit
Assignee: Nobody - feel free to take it CLA
QA Contact:
URL:
Whiteboard: oracle
Keywords:
Depends on:
Blocks:
 
Reported: 2012-01-25 00:40 EST by André de Jager CLA
Modified: 2022-06-09 10:21 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description André de Jager CLA 2012-01-25 00:40:08 EST
Build Identifier: 2.3.2.v20111125-r10461

When creating a criteria query that return the value of an Oracle "TIMESTAMP WITH TIME ZONE" column, a "java.lang.ClassCastException: org.eclipse.persistence.internal.platform.database.oracle.TIMESTAMPTZWrapper cannot be cast to java.util.Calendar" occurs.

Example:
	final CriteriaBuilder builder = em.getCriteriaBuilder();
	final CriteriaQuery<Calendar> query = builder.createQuery(Calendar.class);
	final Root<TestEntity> root = query.from(TestEntity.class);
	query.select(builder.greatest(root.get(TestEntity_.entityDate)));
	// returned type should a Calendar not a TIMESTAMPTZWrapper. throws exception
	final Calendar cal = em.createQuery(query).setMaxResults(1).getSingleResult();

I've tried different Java types (Calendar and Date), Oracle JDBC drivers (OJDBC 11.2.0.3.0 and 10.2.0.4.0), and databases (Oracle Database 10g Release 10.2.0.4.0 - 64bit Production and Oracle Database 10g Express Edition Release 10.2.0.1.0) but the problem keep occurring.

Calendars (and TIMESTAMPTZ) work in subqueries and parameters. A workaround it to create a generic Object criteria query and create the calendar from the TIMESTAMPTZWrapper.

Example workaround:
	final CriteriaBuilder builder = em.getCriteriaBuilder();
	final CriteriaQuery<Object> query = builder.createQuery();
	final Root<TestEntity> root = query.from(TestEntity.class);
	query.select(builder.greatest(root.get(TestEntity_.entityDate)));
	// returned type should a Calendar not a TIMESTAMPTZWrapper
	final TIMESTAMPTZWrapper wrapper = (TIMESTAMPTZWrapper) em.createQuery(query).setMaxResults(1).getSingleResult();
	final Calendar cal = Calendar.getInstance();
	cal.setTimeInMillis(wrapper.getTimestamp().getTime());
	cal.setTimeZone(wrapper.getTimeZone());

See attached example project.

Reproducible: Always

Steps to Reproduce:
1. Download attached project, extract and import into Eclipse
2. Update the the connection details in the "/EclipselinkBug/src/META-INF/persistence.xml" file accordingly
3. Run the bug.eclipselink.TestBug class as a Java Application
Comment 1 André de Jager CLA 2012-01-25 00:47:57 EST
I've uploaded the example project to my Dropbox instead. http://dl.dropbox.com/u/392709/EclipselinkBug.zip
Comment 2 Tom Ware CLA 2012-02-17 10:44:33 EST
Setting target and priority.  See the following page for the meanings of these fields:

http://wiki.eclipse.org/EclipseLink/Development/Bugs/Guidelines

Community: Please vote for this bug if it is important to you.  Votes are one of the main criteria we use to determine which bugs to fix next.
Comment 3 Eclipse Webmaster CLA 2022-06-09 10:21:44 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink