ejbql - 如何在 EJBQL 中将整数转换为字符串

标签 ejbql

我得到了一个带有整数的实体

@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/

相关文章:

java - EJB QL 中不区分大小写的搜索

java - Hibernate:不能对 OFFSET 和 LIMIT 使用命名参数吗?

java - 在 JPQL 中选择 nvl(max(c.EmployeeId),0)?

mysql - 是否有 ifnull() 的替代品

java - EJBQL 命名参数可以在查询中重复吗?

java - Hibernate(JPA)如何进行急切查询,加载所有子对象

java - EJBQL 日期比较