ejbql

How can I cast a Integer to a String in EJBQL


I got a Entity with a Integer

@Entity(name=customer)
public Customer {
    ...
    @Column
    private int number;
    ...
    //getter,setter
}

Now I want to cast this Integer in a query to compare it with an other value.

I tried this Query:

"SELECT c FROM customer c WHERE CAST(c.number AS TEXT) LIKE '1%'"

But it doesn't work.


Solution

  • Since EJB3 EJBQL has been (almost) replaced by JPQL. In EJBQL and according to http://docs.oracle.com/cd/E11035_01/kodo41/full/html/ejb3_langref.html in JPQL as well there is no functionality to CAST a property of an entity.

    So like I already told there are two options left:

    1. Use a native Query.
    2. Add special cast methods to the entities.