Bug 414056 - Wrong UNION sql generation on FirebirdPlatform
Summary: Wrong UNION sql generation on FirebirdPlatform
Status: NEW
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows 7
: P2 blocker with 1 vote (vote)
Target Milestone: ---   Edit
Assignee: Nobody - feel free to take it CLA
QA Contact:
URL:
Whiteboard: firebird
Keywords:
Depends on:
Blocks:
 
Reported: 2013-07-30 14:32 EDT by Beto Neto CLA
Modified: 2022-06-09 10:34 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Beto Neto CLA 2013-07-30 14:32:26 EDT
EclipseLink: 2.5.0
Database: Firebird 2.1.5 Super Server

I'm trying this JPQL:

  select a.Code from EntityA a union select b.Code from EntityB b

This is resulting the SQL below:

  (SELECT t0.CODE FROM TABLE_A t0 UNION (SELECT t1.CODE from TABLE_B t1))

The "("  and ")" cannot be used, the correct SQL must be:

  SELECT t0.CODE FROM TABLE_A t0 UNION SELECT t1.CODE from TABLE_B t1


This this the real exception:

SEVERE: Servlet.service() for servlet [SpringDispatcher] in context with path [/jjwxp-web] threw exception [Request processing failed; nested exception is javax.persistence.PersistenceException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: org.firebirdsql.jdbc.FBSQLException: GDS Exception. 335544569. Dynamic SQL Error
SQL error code = -104
Token unknown - line 1, column 1
(
Error Code: 335544569
Call: (SELECT t0.BIN_IMAGEM_PROIMA FROM PRODUTOS_IMAGENS t0 WHERE (t0.COD_IMAGEM = ?) UNION (SELECT t1.BIN_IMAGEM_PROCORIMA FROM PRODUTOS_CORES_IMAGENS t1 WHERE (t1.COD_IMAGEM = ?)))
	bind => [4, 4]
Query: ReportQuery(referenceClass=ProdutoImagem sql="(SELECT t0.BIN_IMAGEM_PROIMA FROM PRODUTOS_IMAGENS t0 WHERE (t0.COD_IMAGEM = ?) UNION (SELECT t1.BIN_IMAGEM_PROCORIMA FROM PRODUTOS_CORES_IMAGENS t1 WHERE (t1.COD_IMAGEM = ?)))")] with root cause
org.firebirdsql.gds.GDSException: Dynamic SQL Error
SQL error code = -104
Token unknown - line 1, column 1
(
	at org.firebirdsql.gds.impl.wire.AbstractJavaGDSImpl.readStatusVector(AbstractJavaGDSImpl.java:2214)
	at org.firebirdsql.gds.impl.wire.AbstractJavaGDSImpl.receiveResponse(AbstractJavaGDSImpl.java:2164)
	at org.firebirdsql.gds.impl.wire.AbstractJavaGDSImpl.iscDsqlPrepare(AbstractJavaGDSImpl.java:1551)
	at org.firebirdsql.gds.impl.GDSHelper.prepareStatement(GDSHelper.java:190)
	at org.firebirdsql.jdbc.AbstractStatement.prepareFixedStatement(AbstractStatement.java:1441)
	at org.firebirdsql.jdbc.AbstractPreparedStatement.prepareFixedStatement(AbstractPreparedStatement.java:1282)
	at org.firebirdsql.jdbc.AbstractPreparedStatement.<init>(AbstractPreparedStatement.java:138)
	at org.firebirdsql.jdbc.FBPreparedStatement.<init>(FBPreparedStatement.java:45)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
	at org.firebirdsql.jdbc.FBStatementFactory.createPreparedStatement(FBStatementFactory.java:89)
	at org.firebirdsql.jdbc.AbstractConnection.prepareStatement(AbstractConnection.java:1187)
	at org.firebirdsql.jdbc.AbstractConnection.prepareStatement(AbstractConnection.java:942)
	at org.firebirdsql.jdbc.AbstractConnection.prepareStatement(AbstractConnection.java:896)
	at org.firebirdsql.jdbc.AbstractConnection.prepareStatement(AbstractConnection.java:324)
	at org.apache.commons.dbcp.DelegatingConnection.prepareStatement(DelegatingConnection.java:281)
	at org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.prepareStatement(PoolingDataSource.java:313)
	at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.prepareStatement(DatabaseAccessor.java:1551)
	at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.prepareStatement(DatabaseAccessor.java:1500)
	at org.eclipse.persistence.internal.databaseaccess.DatabaseCall.prepareStatement(DatabaseCall.java:778)
	at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:619)
	at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeCall(DatabaseAccessor.java:558)
	at org.eclipse.persistence.internal.sessions.AbstractSession.basicExecuteCall(AbstractSession.java:1995)
	at org.eclipse.persistence.sessions.server.ServerSession.executeCall(ServerSession.java:570)
	at org.eclipse.persistence.sessions.server.ClientSession.executeCall(ClientSession.java:248)
	at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:242)
	at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:228)
	at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeSelectCall(DatasourceCallQueryMechanism.java:299)
	at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.selectAllRows(DatasourceCallQueryMechanism.java:694)
	at org.eclipse.persistence.internal.queries.ExpressionQueryMechanism.selectAllRowsFromTable(ExpressionQueryMechanism.java:2714)
	at org.eclipse.persistence.internal.queries.ExpressionQueryMechanism.selectAllReportQueryRows(ExpressionQueryMechanism.java:2651)
	at org.eclipse.persistence.queries.ReportQuery.executeDatabaseQuery(ReportQuery.java:847)
	at org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:899)
	at org.eclipse.persistence.queries.ObjectLevelReadQuery.execute(ObjectLevelReadQuery.java:1114)
	at org.eclipse.persistence.queries.ReadAllQuery.execute(ReadAllQuery.java:402)
	at org.eclipse.persistence.queries.ObjectLevelReadQuery.executeInUnitOfWork(ObjectLevelReadQuery.java:1202)
	at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:2894)
	at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1797)
	at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1779)
	at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1744)
	at org.eclipse.persistence.internal.jpa.QueryImpl.executeReadQuery(QueryImpl.java:258)
	at org.eclipse.persistence.internal.jpa.QueryImpl.getSingleResult(QueryImpl.java:516)
	at org.eclipse.persistence.internal.jpa.EJBQueryImpl.getSingleResult(EJBQueryImpl.java:400)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:601)
	at org.springframework.orm.jpa.SharedEntityManagerCreator$DeferredQueryInvocationHandler.invoke(SharedEntityManagerCreator.java:310)
	at com.sun.proxy.$Proxy29.getSingleResult(Unknown Source)
Comment 1 Tom Ware CLA 2013-08-15 09:25:51 EDT
You should be able to workaround this issue by extending FirebirdPlatform and enabling your new platform by specifying it's classname with the eclipselink.target-database persistence unit property

In your subclass, you would override the initializePlatformOperators in FirebirdPlatform to call super.initializePlatformOperators() and then add a new operator, much as it is done in our FirebirdPlatform now.

The operator you could create would look something like this:


    public static ExpressionOperator UNION() {
        ListExpressionOperator exOperator = new ListExpressionOperator();
        exOperator.setType(FunctionOperator);
        exOperator.setSelector(ExpressionOperator.Union);
        exOperator.bePrefix();
        exOperator.setNodeClass(ClassConstants.ArgumentListFunctionExpression_Class);
        exOperator.setStartString("UNION");
        exOperator.setSeparator(",");
        exOperator.setTerminationString("");
        return exOperator;
    }
Comment 2 Tom Ware CLA 2013-08-19 10:16:30 EDT
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:34:09 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink