Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 369617

Summary: ClassCastException TIMESTAMPTZWrapper cannot be cast for Oracle TIMESTAMP WITH TIME ZONE columns
Product: z_Archived Reporter: André de Jager <andrethehunter>
Component: EclipselinkAssignee: Nobody - feel free to take it <nobody>
Status: NEW --- QA Contact:
Severity: major    
Priority: P2 CC: andrethehunter, martin.grebac, tom.ware
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard: oracle

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