Bug 258221 - Unable to bind Integer null to a parameter in Query
Summary: Unable to bind Integer null to a parameter in Query
Status: NEW
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Linux
: P2 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-12-09 20:49 EST by A Lazarus CLA
Modified: 2022-06-09 10:04 EDT (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description A Lazarus CLA 2008-12-09 20:49:08 EST
I can't bind NULL as a parameter when compared to an Integer field.

Exception [EclipseLink-4002] (Eclipse Persistence Services - 1.0.1 (Build 20080905)): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: org.postgresql.util.PSQLException: ERROR: operator does not exist: integer = character varying
Error Code: 0
Call: SELECT date, monthly_period, weekly_period, collation, dow, price, adjusted_price, volume, market_cap, lt_collation, security_serial_id, matlab_date FROM raw_price WHERE (security_serial_id = ?) ORDER BY security_serial_id DESC, matlab_date DESC
        bind => [null]

The failure is right after my code

   rawPriceQuery.setParameter("secID", (Integer) null);

and the named Query involved is

        @NamedQuery(
            name = "RawPrice.selectForPrice",
            query =
                "SELECT r FROM RawPrice r WHERE r.rawPricePK.securitySerialId= :secID" +
                " ORDER BY r.rawPricePK.securitySerialId DESC, r.rawPricePK.matlabDate DESC"
        )

security_serial_id is an integer field.
  
TopLink does not complain and behaves as expected.
If I replace the (Integer)null with an integer constant, EclipseLink
does not complain and behaves as expected.
Comment 1 Peter Krogh CLA 2009-11-27 13:54:35 EST
 This bug is being moved to Future where we can properly sort them all together based on community votes and severity. We will then assign them accordingly to future patch sets and releases.
Comment 2 Peter Krogh CLA 2009-11-30 11:36:31 EST
Changing the priority of the bugs that have been recently triaged to future.  Targetting them to P2 will differentiate them from the P3s that have been triaged into future earlier.
Comment 3 Praba Vijayaratnam CLA 2009-12-07 13:19:54 EST
Following tests failed with same exception:
org.eclipse.persistence.testing.tests.jpa.ddlgeneration.DDLGenerationJUnitTestSuite.testDirectCollectionMapping
org.eclipse.persistence.testing.tests.jpa.ddlgeneration.DDLGenerationJUnitTestSuite.testAggregateCollectionMapping
org.eclipse.persistence.testing.tests.jpa.ddlgeneration.DDLGenerationJUnitTestSuite.testOneToManyMapping
org.eclipse.persistence.testing.tests.jpa.ddlgeneration.DDLGenerationJUnitTestSuite.testUnidirectionalOneToManyMapping
org.eclipse.persistence.testing.tests.jpa.ddlgeneration.DDLGenerationJUnitTestSuite.testManyToManyMapping
--------
Internal Exception: org.postgresql.util.PSQLException: ERROR: operator does not exist: character varying = integer Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts. Position: 72 Error Code: 0 Call: SELECT DESCRIPTION, aCMap_KEY FROM MapHolder_ACMAP WHERE (MapHolder_ID = ?) bind => [5] Query: ReadAllQuery(name="aCMap" referenceClass=AggregateMapValue sql="SELECT DESCRIPTION, aCMap_KEY FROM MapHolder_ACMAP WHERE (MapHolder_ID = ?)")

Local Exception Stack:
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.1.0.v20091204-r5981): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: org.postgresql.util.PSQLException: ERROR: operator does not exist: character varying = integer
Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts.
Position: 72
Error Code: 0
Call: SELECT DESCRIPTION, aCMap_KEY FROM MapHolder_ACMAP WHERE (MapHolder_ID = ?)
bind => [5]
Query: ReadAllQuery(name="aCMap" referenceClass=AggregateMapValue sql="SELECT DESCRIPTION, aCMap_KEY FROM MapHolder_ACMAP WHERE (MapHolder_ID = ?)")
at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:333)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.processExceptionForCommError(DatabaseAccessor.java:1415)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:678)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeCall(DatabaseAccessor.java:529)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeCall(AbstractSession.java:914)
at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:205)
at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:191)
at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeSelectCall(DatasourceCallQueryMechanism.java:262)
at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.selectAllRows(DatasourceCallQueryMechanism.java:618)
at org.eclipse.persistence.internal.queries.ExpressionQueryMechanism.selectAllRowsFromTable(ExpressionQueryMechanism.java:2537)
at org.eclipse.persistence.internal.queries.ExpressionQueryMechanism.selectAllRows(ExpressionQueryMechanism.java:2496)
at org.eclipse.persistence.queries.ReadAllQuery.executeObjectLevelReadQuery(ReadAllQuery.java:455)
at org.eclipse.persistence.queries.ObjectLevelReadQuery.executeDatabaseQuery(ObjectLevelReadQuery.java:997)
at org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:675)
at org.eclipse.persistence.queries.ObjectLevelReadQuery.execute(ObjectLevelReadQuery.java:958)
at org.eclipse.persistence.queries.ReadAllQuery.execute(ReadAllQuery.java:432)
at org.eclipse.persistence.internal.sessions.AbstractSession.internalExecuteQuery(AbstractSession.java:2322)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1225)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1207)
at org.eclipse.persistence.queries.ObjectLevelReadQuery.executeInUnitOfWork(ObjectLevelReadQuery.java:1019)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:2863)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1225)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1207)
at org.eclipse.persistence.internal.indirection.QueryBasedValueHolder.instantiate(QueryBasedValueHolder.java:85)
at org.eclipse.persistence.internal.indirection.QueryBasedValueHolder.instantiateForUnitOfWorkValueHolder(QueryBasedValueHolder.java:100)
at org.eclipse.persistence.internal.indirection.UnitOfWorkValueHolder.instantiateImpl(UnitOfWorkValueHolder.java:156)
at org.eclipse.persistence.internal.indirection.UnitOfWorkValueHolder.instantiate(UnitOfWorkValueHolder.java:230)
at org.eclipse.persistence.internal.indirection.DatabaseValueHolder.getValue(DatabaseValueHolder.java:83)
at org.eclipse.persistence.indirection.IndirectMap.buildDelegate(IndirectMap.java:110)
at org.eclipse.persistence.indirection.IndirectMap.getDelegate(IndirectMap.java:316)
at org.eclipse.persistence.indirection.IndirectMap$1.(IndirectMap.java:187)
at org.eclipse.persistence.indirection.IndirectMap.entrySet(IndirectMap.java:186)
at org.eclipse.persistence.internal.queries.MapContainerPolicy$MapContainerPolicyIterator.(MapContainerPolicy.java:811)
at org.eclipse.persistence.internal.queries.MapContainerPolicy.iteratorFor(MapContainerPolicy.java:453)
at org.eclipse.persistence.mappings.AggregateCollectionMapping.cascadePerformRemoveIfRequired(AggregateCollectionMapping.java:379)
at org.eclipse.persistence.internal.descriptors.ObjectBuilder.cascadePerformRemove(ObjectBuilder.java:1485)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.performRemove(UnitOfWorkImpl.java:3561)
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.remove(EntityManagerImpl.java:435)
at org.eclipse.persistence.testing.tests.jpa.ddlgeneration.DDLGenerationJUnitTestSuite.testManyToManyMapping(DDLGenerationJUnitTestSuite.java:767)
at org.eclipse.persistence.testing.framework.junit.JUnitTestCase.runBare(JUnitTestCase.java:428)
at org.eclipse.persistence.testing.framework.TestExecutor.execute(TestExecutor.java:248)
at org.eclipse.persistence.testing.framework.TestModel.execute(TestModel.java:208)
at org.eclipse.persistence.testing.framework.TestCollection.run(TestCollection.java:313)
Caused by: org.postgresql.util.PSQLException: ERROR: operator does not exist: character varying = integer
Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts.
Position: 72
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2062)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1795)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:257)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:479)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:367)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:271)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeSelect(DatabaseAccessor.java:891)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:601)
Comment 4 James Sutherland CLA 2010-05-31 13:28:10 EDT
SVN mina commit: Bug#305908, 296281, 297080, 297093, 258221, PostgreSQL, DB2, Derby failures

https://bugs.eclipse.org/bugs/show_bug.cgi?id=258221

Fixed a bunch of test failures from PostgreSQL, DB2, Derby platforms.

Changes:
- Added generics to Project and Session variables
- Changed toNumber test to convert a String to number (instead of a number to number)
- Changed testing tool logging to not log thread info unless finest
- Added type initialization for MapKey and AggregateCollection, type was getting defaulted to String, given bad DDL and incorrect typing
- Removed dead MapKey code in mappings
- Fixed trim function in DB2
- Fixed locate function in Postgres
- Added session default timeout to Session interface
- Disable session default timeout for Postgres
- Avoid distinct JPQL test on Derby
Comment 5 James Sutherland CLA 2010-05-31 13:41:16 EDT
Hmm, noticed that this test error was logged under a user error.

The two errors have nothing to do with eachother, I fixed the test failure, which was an issue in setting the type correctly for element collections, and map keys.

The user error is that the null type is being defaulted to VARCHAR, as we do not know the type.  Note that cast to Integer,

rawPriceQuery.setParameter("secID", (Integer) null);

 does absolutely nothing, as the setParameter is just passed a null.

We should be getting the type from the other side of the relation from the mapping though, there could be an issue there.

However an = NULL comparison will have issues on most databases, normally IS NULL is required.  If this named query allows null, then it may need to set shouldPrepare (hint "eclipselink.prepare") to false in the query.

Leaving this bug as open.
Comment 6 Bernard Missing name CLA 2011-11-22 19:11:51 EST
Even when the JPQL parameter is guarded with IS NULL, EclipseLink has issues with Postgresql and Derby. Please see https://bugs.eclipse.org/bugs/show_bug.cgi?id=362414
Comment 7 Eclipse Webmaster CLA 2022-06-09 10:04:52 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink