Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 331575 - ClassCastException when aliasing select expression items
Summary: ClassCastException when aliasing select expression items
Status: CLOSED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: All All
: P3 normal with 2 votes (vote)
Target Milestone: ---   Edit
Assignee: Nobody - feel free to take it CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-12-01 12:35 EST by Pascal Filion CLA
Modified: 2022-06-09 10:35 EDT (History)
6 users (show)

See Also:


Attachments
proposed fix (18.88 KB, patch)
2011-07-19 13:57 EDT, Tom Ware CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Pascal Filion CLA 2010-12-01 12:35:18 EST
Build Identifier: 2.1.2.v20101104-r8475

org.eclipse.persistence.internal.jpa.parsing.Node
 isAliasableNode() : returns true by default but should return false

Reproducible: Always

Steps to Reproduce:
Try to parse "SELECT e.salary / 1000D n From Employee e" and a Class cast exception is thrown:

Caused by: java.lang.ClassCastException: org.eclipse.persistence.internal.jpa.parsing.DivideNode cannot be cast to org.eclipse.persistence.internal.jpa.parsing.AliasableNode
	at org.eclipse.persistence.internal.jpa.parsing.SelectNode.applyToQuery(SelectNode.java:171)
	at org.eclipse.persistence.internal.jpa.parsing.ParseTree.applyQueryNodeToQuery(ParseTree.java:334)
	at org.eclipse.persistence.internal.jpa.parsing.JPQLParseTree.populateReadQueryInternal(JPQLParseTree.java:113)
	at org.eclipse.persistence.internal.jpa.parsing.JPQLParseTree.populateQuery(JPQLParseTree.java:84)
	at org.eclipse.persistence.internal.jpa.EJBQueryImpl.buildEJBQLDatabaseQuery(EJBQueryImpl.java:211)
	at org.eclipse.persistence.internal.jpa.JPAQuery.processJPQLQuery(JPAQuery.java:106)
	at org.eclipse.persistence.internal.jpa.JPAQuery.prepare(JPAQuery.java:90)
	at org.eclipse.persistence.queries.DatabaseQuery.checkPrepare(DatabaseQuery.java:509)
Comment 1 Tom Ware CLA 2010-12-09 09:11:48 EST
Setting target and priority.  See the following page for the meanings of these fields:

http://wiki.eclipse.org/EclipseLink/Development/Bugs/Guidelines
Comment 2 Pascal Filion CLA 2010-12-13 12:11:08 EST
I think EclipseLink parsing system doesn't parse the result variable from a JPA 2.0 JPQL query. It can't parse the following query:

SELECT MOD(a.id, 2) AS m FROM Address a JOIN FETCH a.customerList ORDER BY m

Internal Exception: java.lang.ClassCastException: org.eclipse.persistence.internal.jpa.parsing.ModNode cannot be cast to org.eclipse.persistence.internal.jpa.parsing.AliasableNode
Query: JPAQuery(name="address.joinFetch" )
	at org.eclipse.persistence.exceptions.QueryException.prepareFailed(QueryException.java:1542)
	at org.eclipse.persistence.queries.DatabaseQuery.checkPrepare(DatabaseQuery.java:589)
	at org.eclipse.persistence.queries.DatabaseQuery.checkPrepare(DatabaseQuery.java:537)
	at org.eclipse.persistence.internal.sessions.AbstractSession.processJPAQueries(AbstractSession.java:2162)
	at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:409)
	at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:386)
	at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.getServerSession(EntityManagerFactoryImpl.java:185)
Comment 3 Pascal Filion CLA 2010-12-13 13:25:45 EST
Note: Should be FETCH JOIN
Comment 4 Chris Delahunt CLA 2011-03-16 12:19:02 EDT
Bug is more that the JPA 2.0 specification requires any select_expression to be aliasable, but only the DotNode and AggregateNodes implement the AliasableNode.  Node should implement AliasableNode (or it done away with entirely), and isAliasableNode return false on nodes that cannot be select_expressions (if there are any).
Comment 5 Matthew North CLA 2011-05-18 09:12:15 EDT
Another way to reproduce this issue, using the JPQL 'FUNC' keyword:

SELECT FUNC('ISNULL', MAX(e.TableID), 0) AS maxId FROM EntityTable e;

The above causes:

java.lang.ClassCastException: org.eclipse.persistence.internal.jpa.parsing.FuncNode cannot be cast to org.eclipse.persistence.internal.jpa.parsing.AliasableNode


Eliminating the 'AS maxId' alias specifier in the query makes the error go away:

SELECT FUNC('ISNULL', MAX(e.TableID), 0) FROM EntityTable e;
Comment 6 Peter Krogh CLA 2011-06-20 14:24:08 EDT
bug scrub
Comment 7 Tom Ware CLA 2011-07-19 13:57:15 EDT
Created attachment 199925 [details]
proposed fix
Comment 8 Tom Ware CLA 2011-07-19 14:22:01 EDT
Fix checked in to 2.3.1 and trunk

Fix makes all NOdes that are selectable implement AliasableNode

Reviewed by Guy Pelletier

Tested with JPA LRG

Added test to JUNitJPQLComplexTestSuite
Comment 9 Eclipse Webmaster CLA 2022-06-09 10:35:46 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink