ximarin
ximarin

Reputation: 401

Criteria API: use greaterThan on a char column

I have to rebuild a query, except for one line everything works fine.

Here the line in sql:

... 
AND someId > '0'
...

someId is a char-field that mostly contains numbers, but sometimes trailing characters. My criteria-part of that looks like this:

cb.greaterThan(myClass.get(MyClass_.someId), 0)

which results in

... 
AND someId > 0 
... 

(regard the missing ')

This screws up the query as I can't use the greaterThan on a char-column.

What I need are all someIds that are just made of numbers and do not contain any letters.

I tried adding a

cb.function("isNumeric", Boolean.class, myClass.get(MyClass_.someId))

to my where-clauses, but the cb.and doesnt like that. :)

Any ideas?

Upvotes: 0

Views: 192

Answers (1)

ximarin
ximarin

Reputation: 401

To answer myself:

I tweaked the isNumeric-thing to this

c.equal(cb.function("isNumeric", Boolean.class, myClass.get(MyClass_.someId)), 1)

and this works fine.

Upvotes: 1

Related Questions