I am a first time user of the new JPA 2.0 Criteria API and I \'m running into a problem when I need to cast a number field to String to compare it with a String parameter. R
What it comes to JPA, Expression.as method is used to serve wrong purpose in question. Casting Expression<Number> to Expression<String> is not supposed to work via Expression.as. Of course it would be nice to have clear error message instead of incorrect JPQL.
As said in documentation, it performs typecast, which is different concept than conversion from type to other:
Perform a typecast upon the expression, returning a new expression object. This method does not cause type conversion: the runtime type is not changed. Warning: may result in a runtime failure.
As axtavt stated in the comments in the question, it is a bug in Hibernate 3.6 http://opensource.atlassian.com/projects/hibernate/browse/HHH-5755