使用 Int 的 Java jSF NamedQuery

发布于 2024-11-01 20:39:03 字数 408 浏览 9 评论 0原文

我正在对一个整数进行搜索查询。这是 Factuur 类中的 NamedQuery:

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

})

因此,“periode”是 Factuur 类中的一个整数,我尝试这样做:

    + "f.periode = :periode AND "

我没有得到异常,我只是从数据库中得不到任何结果,而应该有...

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

千年*琉璃梦 2024-11-08 20:39:03

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

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

 字符串表达式 [NOT] LIKE 模式值 [ESCAPE 转义字符]

string_expression 必须具有字符串值。

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文