| Summary: | Enum constant processing breaks when toString() has been overriden | ||
|---|---|---|---|
| Product: | z_Archived | Reporter: | Nikita Zinoviev <nikita.zinoviev> |
| Component: | Eclipselink | Assignee: | Nobody - feel free to take it <nobody> |
| Status: | CLOSED DUPLICATE | QA Contact: | |
| Severity: | normal | ||
| Priority: | P2 | CC: | tom.ware |
| Version: | unspecified | ||
| Target Milestone: | --- | ||
| Hardware: | PC | ||
| OS: | Mac OS X - Carbon (unsup.) | ||
| Whiteboard: | |||
Setting target and priority. See the following page for the meanings of these fields: http://wiki.eclipse.org/EclipseLink/Development/Bugs/Guidelines *** This bug has been marked as a duplicate of bug 332207 *** The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink |
Build Identifier: 2.1.0-M7 I have an enum class with overriden toString() which prints out the value in a user friendly form (say "Closed" for CLOSED enum constant). When I try to use it inside a query ... WHERE entity.status=mypackage.Myenum.CLOSED I get an error Caused by: Exception [EclipseLink-8015] (Eclipse Persistence Services - 2.1.0.v20100127-r6421): org.eclipse.persistence.exceptions.JPQLException Exception Description: Error compiling the query [SELECT .. FROM myEntity entity WHERE entity.status=mypackage.Myenum.CLOSED], line 1, column 88: invalid enum literal, the enum type mypackage.Myenum.CLOSED does not have an enum literal CLOSED. at org.eclipse.persistence.exceptions.JPQLException.invalidEnumLiteral(JPQLException.java:260) at org.eclipse.persistence.internal.jpa.parsing.DotNode.validate(DotNode.java:91) at org.eclipse.persistence.internal.jpa.parsing.Node.validate(Node.java:94) at org.eclipse.persistence.internal.jpa.parsing.BinaryOperatorNode.validate(BinaryOperatorNode.java:34) at org.eclipse.persistence.internal.jpa.parsing.EqualsNode.validate(EqualsNode.java:41) at org.eclipse.persistence.internal.jpa.parsing.WhereNode.validate(WhereNode.java:34) at org.eclipse.persistence.internal.jpa.parsing.ParseTree.validate(ParseTree.java:211) at org.eclipse.persistence.internal.jpa.parsing.ParseTree.validate(ParseTree.java:187) at org.eclipse.persistence.internal.jpa.parsing.ParseTree.validate(ParseTree.java:177) at org.eclipse.persistence.internal.jpa.parsing.JPQLParseTree.populateReadQueryInternal(JPQLParseTree.java:110) at org.eclipse.persistence.internal.jpa.parsing.JPQLParseTree.populateQuery(JPQLParseTree.java:84) at org.eclipse.persistence.internal.jpa.EJBQueryImpl.buildEJBQLDatabaseQuery(EJBQueryImpl.java:207) at org.eclipse.persistence.internal.jpa.EJBQueryImpl.buildEJBQLDatabaseQuery(EJBQueryImpl.java:178) at org.eclipse.persistence.internal.jpa.EJBQueryImpl.<init>(EJBQueryImpl.java:130) at org.eclipse.persistence.internal.jpa.EJBQueryImpl.<init>(EJBQueryImpl.java:114) at org.eclipse.persistence.internal.jpa.EntityManagerImpl.createQuery(EntityManagerImpl.java:1338) When I looked at /Users/nikitazinoviev/.m2/repository/org/eclipse/persistence/eclipselink/2.1.0-M7/eclipselink-2.1.0-M7-sources.jar!/org/eclipse/persistence/internal/jpa/parsing/TypeHelperImpl.java I found /** Returns the enum constant if the specified type denotes an enum type * and the specified constant denotes a constant of the enum type. */ public Object resolveEnumConstant(Object type, String constant) { Class clazz = getJavaClass(type); Object[] constants = clazz.getEnumConstants(); if (constants != null) { for (int i = 0; i < constants.length; i++) { if (constant.equals(constants[i].toString())) { return constants[i]; } } } return null; } probably this method should cast to Enum and use name() instead of toString(). Reproducible: Always Steps to Reproduce: 1. Create an enum overriding toString(). 2. Add a field of this type to some JPA entity via @Enumerated(EnumType.STRING) private MyEnum status; 3. Execute a query with ... WHERE entity.status=mypackage.Myenum.CLOSED