2

Is it possible to use casts in JPQL? In HQL it seems to be supported

cast(... as ...), where the second argument is the name of a Hibernate type, and extract(... from ...) if ANSI cast() and extract() is supported by the underlying database

source : Hibernate reference

My target JPA provider is EclipseLink, so any EclipseLink specific solution is ok as well.

Timo Westkämper
  • 21,824
  • 5
  • 78
  • 111

3 Answers3

3

According to the specification of JPA/JPA2, JPQL is not supporting query casts. However, the most recent EclipseLink Release 2.1.0 does have a propritary support for downcasts in JPQL and expressions, please look here

MRalwasser
  • 15,605
  • 15
  • 101
  • 147
  • Thanks for the answer, but I am searching here for literal casts. There is a related open bug now : https://bugs.eclipse.org/bugs/show_bug.cgi?id=315087 – Timo Westkämper Jun 29 '10 at 19:18
1

Literal downcasts in EclipseLink JPQL are currently not supported, but might be if the following issue gets resolved : https://bugs.eclipse.org/bugs/show_bug.cgi?id=315087

Timo Westkämper
  • 21,824
  • 5
  • 78
  • 111
1

It should be supported using JPA 2.1 TREAT operator.

Ondrej Bozek
  • 10,987
  • 7
  • 54
  • 70