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...

4

1 回答 1

0

JPA 规范的第 4.6.9 节规定 LIKE 运算符只能应用于字符串类型的表达式:

在条件表达式中使用比较运算符 [NOT] LIKE 的语法如下:

      string_expression [NOT] LIKE pattern_value [ESCAPE escape_character]

string_expression 必须有一个字符串值。

似乎没有将整数转换为字符串的函数。如果您要查询一个范围,您可能应该计算应用程序中的下限值和上限值,并使用 BETWEEN 表达式进行查询。如果您需要使用任意 LIKE 表达式进行查询,那么您的字段可能应该是字符串类型。

于 2011-04-18T11:36:54.763 回答