java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Enum Query: ReadAllQuery(name="MyEntity.findEnum" referenceClass=MyEntity jpql="SELECT myEntity FROM MyEntity myEntity WHERE myEntity.myEnum = 'ENUM'")

Stack Overflow | Display Name | 8 months ago
tip
Do you know that we can give you better hits? Get more relevant results from Samebug’s stack trace search.
  1. 0

    Java: Have the @Enumerated(STRING) but still get ClassCastException

    Stack Overflow | 8 months ago | Display Name
    java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Enum Query: ReadAllQuery(name="MyEntity.findEnum" referenceClass=MyEntity jpql="SELECT myEntity FROM MyEntity myEntity WHERE myEntity.myEnum = 'ENUM'")

    1 unregistered visitors

    Root Cause Analysis

    1. java.lang.ClassCastException

      java.lang.String cannot be cast to java.lang.Enum

      at org.eclipse.persistence.mappings.converters.EnumTypeConverter.convertObjectValueToDataValue()
    2. EclipseLink (non-OSGi)
      EntityManagerImpl.createNamedQuery
      1. org.eclipse.persistence.mappings.converters.EnumTypeConverter.convertObjectValueToDataValue(EnumTypeConverter.java:160)
      2. org.eclipse.persistence.mappings.foundation.AbstractDirectMapping.getFieldValue(AbstractDirectMapping.java:776)
      3. org.eclipse.persistence.internal.expressions.QueryKeyExpression.getFieldValue(QueryKeyExpression.java:420)
      4. org.eclipse.persistence.internal.expressions.ConstantExpression.printSQL(ConstantExpression.java:152)
      5. org.eclipse.persistence.expressions.ExpressionOperator.printDuo(ExpressionOperator.java:2239)
      6. org.eclipse.persistence.internal.expressions.CompoundExpression.printSQL(CompoundExpression.java:286)
      7. org.eclipse.persistence.internal.expressions.RelationExpression.printSQL(RelationExpression.java:899)
      8. org.eclipse.persistence.internal.expressions.ExpressionSQLPrinter.translateExpression(ExpressionSQLPrinter.java:306)
      9. org.eclipse.persistence.internal.expressions.ExpressionSQLPrinter.printExpression(ExpressionSQLPrinter.java:129)
      10. org.eclipse.persistence.internal.expressions.SQLSelectStatement.printSQL(SQLSelectStatement.java:1683)
      11. org.eclipse.persistence.internal.databaseaccess.DatabasePlatform.printSQLSelectStatement(DatabasePlatform.java:3178)
      12. org.eclipse.persistence.platform.database.PostgreSQLPlatform.printSQLSelectStatement(PostgreSQLPlatform.java:530)
      13. org.eclipse.persistence.internal.expressions.SQLSelectStatement.buildCall(SQLSelectStatement.java:782)
      14. org.eclipse.persistence.internal.expressions.SQLSelectStatement.buildCall(SQLSelectStatement.java:792)
      15. org.eclipse.persistence.descriptors.ClassDescriptor.buildCallFromStatement(ClassDescriptor.java:813)
      16. org.eclipse.persistence.internal.queries.StatementQueryMechanism.setCallFromStatement(StatementQueryMechanism.java:390)
      17. org.eclipse.persistence.internal.queries.StatementQueryMechanism.prepareSelectAllRows(StatementQueryMechanism.java:315)
      18. org.eclipse.persistence.internal.queries.ExpressionQueryMechanism.prepareSelectAllRows(ExpressionQueryMechanism.java:1721)
      19. org.eclipse.persistence.queries.ReadAllQuery.prepareSelectAllRows(ReadAllQuery.java:813)
      20. org.eclipse.persistence.queries.ReadAllQuery.prepare(ReadAllQuery.java:744)
      21. org.eclipse.persistence.queries.DatabaseQuery.checkPrepare(DatabaseQuery.java:661)
      22. org.eclipse.persistence.queries.ObjectLevelReadQuery.checkPrepare(ObjectLevelReadQuery.java:901)
      23. org.eclipse.persistence.queries.DatabaseQuery.checkPrepare(DatabaseQuery.java:613)
      24. org.eclipse.persistence.internal.jpa.QueryImpl.getDatabaseQueryInternal(QueryImpl.java:341)
      25. org.eclipse.persistence.internal.jpa.EntityManagerImpl.createNamedQuery(EntityManagerImpl.java:1124)
      26. org.eclipse.persistence.internal.jpa.EntityManagerImpl.createNamedQuery(EntityManagerImpl.java:1144)
      26 frames
    3. com.istvanmosonyi.dbtest
      Main.main
      1. com.istvanmosonyi.dbtest.Main.main(Main.java:29)
      1 frame