我想通过使用类属性的函数来排序查询。像这样的东西:
@entity
class A
{
private int id;
private String name;
public int StringLength()
{
return name.length();
}
}
句子类似于:select n from A order by name.StringLength()
。可能吗?
最佳答案
不,你不能,但如果你想根据其中一个属性的长度进行查询,你可以使用类似于 SQL 的长度函数:
select n from A order by length(name)
关于java - 我可以在 EJBQL 中通过未映射到数据库列的函数进行排序吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1715595/