Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Enumerated(EnumType.String) annotation not working in 2.3.0(Criteriabuilder.selectCase() does not honour @Enumerated(EnumType.String) annotation)
Enumerated(EnumType.String) annotation not working in 2.3.0 [message #753972] Mon, 31 October 2011 10:07 Go to next message
Anatol Missing name is currently offline Anatol Missing nameFriend
Messages: 4
Registered: October 2011
Junior Member
Hello.

Using EclipseLink 2.3.0 I get the following SQLSyntaxException, using EclipseLink 2.1.3 it works fine.

Quote:

Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.0.v20110604-r9504): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLSyntaxErrorException: Comparisons between 'VARCHAR (UCS_BASIC)' and 'INTEGER' are not supported. Types must be comparable.
[...]


The respective call looks like this (full project attached).

  CriteriaBuilder cb = em.getCriteriaBuilder();
  CriteriaQuery<X1EnumEntity[]> query = cb.createQuery(X1EnumEntity[].class);
  Root<X1EnumEntity> from = query.from(X1EnumEntity.class);

  Expression<Object> isLoaded =
    cb.selectCase().when(cb.equal(from.get("x1"), X1Enum.GREEN), Long.valueOf(1)).otherwise(Long.valueOf(0));

  query.multiselect(isLoaded);
  em.createQuery(query).getResultList();


The generated SQL statement is

EclipseLink 2.3.0: SELECT CASE WHEN (X1 = 0) THEN 1 ELSE 0 END FROM X1ENUMENTITY
EclipseLink 2.1.3: SELECT CASE WHEN (X1 = GREEN) THEN 1 ELSE 0 END FROM X1ENUMENTITY

The Entity field X1EnumEntity.x1 is annotated as follows

  @Column
  @Enumerated(EnumType.STRING)
  private X1Enum x1;


Why is the when-condition using the ordinal instead of the name of the enum case? Is the @Enumerated(EnumType.String) annotation not honoured in a selectcase any more? Is that a bug or a feature?

Thanks for your help,
Anatol


STACKTRACE:

Local Exception Stack:
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.0.v20110604-r9504): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLSyntaxErrorException: Comparisons between 'VARCHAR (UCS_BASIC)' and 'INTEGER' are not supported. Types must be comparable. String types must also have matching collation. If collation does not match, a possible solution is to cast operands to force them to the default collation (e.g. SELECT tablename FROM sys.systables WHERE CAST(tablename AS VARCHAR(128)) = 'T1')
Error Code: 20000
Call: SELECT CASE WHEN (X1 = 0) THEN 1 ELSE 0 END FROM X1ENUMENTITY
Query: ReportQuery(referenceClass=X1EnumEntity sql="SELECT CASE WHEN (X1 = ?) THEN ? ELSE ? END FROM X1ENUMENTITY")
at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:333)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:644)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeCall(DatabaseAccessor.java:535)
at org.eclipse.persistence.internal.sessions.AbstractSession.basicExecuteCall(AbstractSession.java:1702)
at org.eclipse.persistence.sessions.server.ClientSession.executeCall(ClientSession.java:253)
at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:207)
at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:193)
at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeSelectCall(DatasourceCallQueryMechanism.java:264)
at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.selectAllRows(DatasourceCallQueryMechanism.java:646)
at org.eclipse.persistence.internal.queries.ExpressionQueryMechanism.selectAllRowsFromTable(ExpressionQueryMechanism.java:2592)
at org.eclipse.persistence.internal.queries.ExpressionQueryMechanism.selectAllReportQueryRows(ExpressionQueryMechanism.java:2535)
at org.eclipse.persistence.queries.ReportQuery.executeDatabaseQuery(ReportQuery.java:846)
at org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:829)
at org.eclipse.persistence.queries.ObjectLevelReadQuery.execute(ObjectLevelReadQuery.java:1056)
at org.eclipse.persistence.queries.ReadAllQuery.execute(ReadAllQuery.java:390)
at org.eclipse.persistence.queries.ObjectLevelReadQuery.executeInUnitOfWork(ObjectLevelReadQuery.java:1144)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:2863)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1501)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1483)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1457)
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.executeReadQuery(EJBQueryImpl.java:485)
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.getResultList(EJBQueryImpl.java:742)
at EclipseLinkEnumTest.JPAhandler.enumExec(JPAhandler.java:42)
at EclipseLinkEnumTest.X1EnumEntityTest.testEnumExec(X1EnumEntityTest.java:13)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.sql.SQLSyntaxErrorException: Comparisons between 'VARCHAR (UCS_BASIC)' and 'INTEGER' are not supported. Types must be comparable. String types must also have matching collation. If collation does not match, a possible solution is to cast operands to force them to the default collation (e.g. SELECT tablename FROM sys.systables WHERE CAST(tablename AS VARCHAR(128)) = 'T1')
at org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedConnection.handleException(Unknown Source)
at org.apache.derby.impl.jdbc.ConnectionChild.handleException(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedStatement.execute(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedStatement.executeQuery(Unknown Source)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeSelect(DatabaseAccessor.java:929)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:607)
... 44 more
Caused by: java.sql.SQLException: Comparisons between 'VARCHAR (UCS_BASIC)' and 'INTEGER' are not supported. Types must be comparable. String types must also have matching collation. If collation does not match, a possible solution is to cast operands to force them to the default collation (e.g. SELECT tablename FROM sys.systables WHERE CAST(tablename AS VARCHAR(128)) = 'T1')
at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcrossDRDA(Unknown Source)
... 54 more
Caused by: ERROR 42818: Comparisons between 'VARCHAR (UCS_BASIC)' and 'INTEGER' are not supported. Types must be comparable. String types must also have matching collation. If collation does not match, a possible solution is to cast operands to force them to the default collation (e.g. SELECT tablename FROM sys.systables WHERE CAST(tablename AS VARCHAR(128)) = 'T1')
at org.apache.derby.iapi.error.StandardException.newException(Unknown Source)
at org.apache.derby.impl.sql.compile.BinaryComparisonOperatorNode.bindComparisonOperator(Unknown Source)
at org.apache.derby.impl.sql.compile.BinaryComparisonOperatorNode.bindExpression(Unknown Source)
at org.apache.derby.impl.sql.compile.ConditionalNode.bindExpression(Unknown Source)
at org.apache.derby.impl.sql.compile.ResultColumn.bindExpression(Unknown Source)
at org.apache.derby.impl.sql.compile.ResultColumnList.bindExpressions(Unknown Source)
at org.apache.derby.impl.sql.compile.SelectNode.bindExpressions(Unknown Source)
at org.apache.derby.impl.sql.compile.DMLStatementNode.bindExpressions(Unknown Source)
at org.apache.derby.impl.sql.compile.DMLStatementNode.bind(Unknown Source)
at org.apache.derby.impl.sql.compile.CursorNode.bindStatement(Unknown Source)
at org.apache.derby.impl.sql.GenericStatement.prepMinion(Unknown Source)
at org.apache.derby.impl.sql.GenericStatement.prepare(Unknown Source)
at org.apache.derby.impl.sql.conn.GenericLanguageConnectionContext.prepareInternalStatement(Unknown Source)
... 48 more

  • Attachment: Enum.zip
    (Size: 8.54KB, Downloaded 269 times)
Re: Enumerated(EnumType.String) annotation not working in 2.3.0 [message #754055 is a reply to message #753972] Mon, 31 October 2011 15:39 Go to previous messageGo to next message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

That is odd, it should use the correct type. Does it use the String value for inserts/updates? Does JPQL work?

Please log a bug for this and vote for it. You may also wish to try the latest patch or build to see if it has been fixed.


James : Wiki : Book : Blog : Twitter
Re: Enumerated(EnumType.String) annotation not working in 2.3.0 [message #754079 is a reply to message #754055] Mon, 31 October 2011 16:42 Go to previous message
Anatol Missing name is currently offline Anatol Missing nameFriend
Messages: 4
Registered: October 2011
Junior Member
Using select() works:

        CriteriaBuilder cb0 = em.getCriteriaBuilder();
        CriteriaQuery<X1EnumEntity> query0 = cb0.createQuery(X1EnumEntity.class);
        Root<X1EnumEntity> entity = query0.from(X1EnumEntity.class);

        query0.select(entity).where(cb0.equal(entity.get("x1"), X1Enum.GREEN));
        em.createQuery(query0).getResultList();


JPQL works as well:

        String queryString = "SELECT var, CASE WHEN (var.x1 = :value) THEN 1 ELSE 0 END FROM X1EnumEntity var";
        Query query1 = em.createQuery(queryString);

        query1.setParameter("value", X1Enum.GREEN);
        List<String> list = query1.getResultList();


Same situation with EclipseLink 2.4.0.v20110922-r10146 Sad


Bug filed under #362498

Previous Topic:Attributes missing in metamodel using IBM JDK
Next Topic:Calling a stored procedure with BLOB input parameter
Goto Forum:
  


Current Time: Fri Apr 19 03:31:49 GMT 2024

Powered by FUDForum. Page generated in 0.02006 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top