I do have a static metamodel with a NUMBER (actually, BigDecimal, don't ask why) column. Now I would like to do a LIKE query against that number column:
CriteriaBuilder cb;
cb.like(entity.get(Entity_.numbercol), "123%");
where entity.get(Entity_.numbercol)
returns a Path<BigDecimal>
. Naturally, I get a compile error: ...like(Expression<String>, ...) ... not applicable for the arguments (Path<BigDecimal>, ...)
Casting the column with .as(String.class)
fails due to some Bug in JPA, but I don't have the bug number at hands right now. It is not fixed in the latest version of JPA/Hibernate, though. Anyway, it results in a runtime exception about some invalid SQL statement being generated.
Now I just need a way to get the criteria API equivalent of the SQL
... WHERE numbercol LIKE '123%';
Searching for the topic already brought up the following responses, which don't help because I have a static metamodel: NHibernate - easiest way to do a LIKE search against an integer column with Criteria API? and JPA/Criteria API - Like & equal problem
Any ideas?
Thanks in advance Dominik