使用 Int 的 Java jSF NamedQuery
我正在对一个整数进行搜索查询。这是 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
JPA 规范第 4.6.9 节规定,LIKE 运算符只能应用于字符串类型的表达式:
似乎没有将整数转换为字符串的函数。如果您正在查询一个范围,您可能应该计算应用程序中的下限值和上限值,并使用 BETWEEN 表达式进行查询。如果您需要使用任意 LIKE 表达式进行查询,那么您的字段可能应该是字符串类型。
Section 4.6.9 of the JPA specification states that the LIKE operator can only be applied to expressions of type string:
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.