Using JPA 2.0 Criteria API and cast causes generated JPQL to fail in Hibernate

前端 未结 2 527
我在风中等你
我在风中等你 2020-12-04 02:11

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

相关标签:
2条回答
  • 2020-12-04 02:25

    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.

    0 讨论(0)
  • 2020-12-04 02:36

    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

    0 讨论(0)
提交回复
热议问题