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

非 Y 不嫁゛ 提交于 2019-11-27 16:06:57

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!