我得到了一个带有整数的实体
@Entity(name=customer)
public Customer {
...
@Column
private int number;
...
//getter,setter
}
现在我想在查询中转换这个 Integer 以将它与其他值进行比较。
我试过这个查询:
"SELECT c FROM customer c WHERE CAST(c.number AS TEXT) LIKE '1%'"
但它不起作用。
最佳答案
这在我使用 Hibernate 的一些代码中有效:
SELECT c FROM customer c WHERE STR(c.number) LIKE '1%'
一般来说,这就是Hibernate docs (14.10 表达式)在类型转换时说:
str() for converting numeric or temporal values to a readable string
cast(... as ...), where the second argument is the name of a Hibernate type, and extract(... from ...) if ANSI cast() and extract() is supported by the underlying database
关于ejbql - 如何在 EJBQL 中将整数转换为字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11278645/