1

I am making a search query for a integer. This is the NamedQuery in the class Factuur:

@NamedQueries({
@NamedQuery(name = "getFactuurs", query = "SELECT f FROM Factuur f WHERE "
+ "f.periode LIKE :periode AND "
+ "f.carTracker.kenteken LIKE :carTrackerKenteken")

})

So the 'periode' is an Integer in the class Factuur, I have tried to do it this way:

    + "f.periode = :periode AND "

I don't get an Exception, I just get nothing from the database, while there should be...

Tom
  • 11
  • 2
  • Are you sure that there is at least one record in the db which matches the values of `periode` and the `carTrackerKenteken` you pass in? – Cristian Boariu Apr 18 '11 at 11:15

1 Answers1

0

Section 4.6.9 of the JPA specification states that the LIKE operator can only be applied to expressions of type string:

The syntax for the use of the comparison operator [NOT] LIKE in a conditional expression is as follows:

      string_expression [NOT] LIKE pattern_value [ESCAPE escape_character]

The string_expression must have a string value.

There does not seem to be a function to convert an integer to a string. If you are querying for a range you should probably calculate the lower and upper values in your application and query with a BETWEEN expression. If you need to query with arbitrary LIKE expressions then your field should probably be of type string.

Community
  • 1
  • 1
Jörn Horstmann
  • 33,639
  • 11
  • 75
  • 118