Using: Hibernate 3.2 CR4 / hibernate-annotations-3.2.0.CR1
According to Java EE 5 Tutorial & Specs
enums should be allowed in static JPQL queries:
Quote:
Enum Literals
The Java Persistence Query Language supports the use of enum literals using the Java enum literal syntax. The enum class name must be specified as fully qualified class name.
Code:
SELECT e
FROM Employee e
WHERE e.status = com.xyz.EmployeeStatus.FULL_TIME
(
http://java.sun.com/javaee/5/docs/tutor ... ml#wp80051)
Having for example:
Code:
package test;
enum Status {
ACTIVE, DELETED
}
@Entity
@NamedQueries( {
@NamedQuery(name="Country.selectAll",
query="SELECT c from Country c " +
"WHERE c.status = test.Status.ACTIVE" ),
class Country {
...
@Enumerated
Status status;
}
This kind of exception is throwed:
Code:
15:59:45,823 ERROR [SessionFactoryImpl] Error in named query: Country.selectAll
org.hibernate.QueryException: Could not format constant value to SQL literal: . [SELECT c from test.Country c WHERE c.status = test.Status.ACTIVE]
at org.hibernate.hql.ast.util.LiteralProcessor.setConstantValue(LiteralProcessor.java:177)
at org.hibernate.hql.ast.util.LiteralProcessor.lookupConstant(LiteralProcessor.java:114)
at org.hibernate.hql.ast.tree.DotNode.resolve(DotNode.java:178)
at org.hibernate.hql.ast.tree.FromReferenceNode.resolve(FromReferenceNode.java:94)
....
Does it mean JBoss EJB 3.0 is not 100% compatible with the specs, therefore I should use some kind of enum UserTypes (what is against the spirit of EJB3) or, what is worse, use parameters+dynamic queries?
Thanks for help,
Konrad