【发布时间】:2009-11-11 14:40:41
【问题描述】:
我想通过使用类属性的函数来订购查询。比如:
@entity
class A
{
private int id;
private String name;
public int StringLength()
{
return name.length();
}
}
句子类似于:select n from A order by name.StringLength()。有可能吗?
【问题讨论】:
我想通过使用类属性的函数来订购查询。比如:
@entity
class A
{
private int id;
private String name;
public int StringLength()
{
return name.length();
}
}
句子类似于:select n from A order by name.StringLength()。有可能吗?
【问题讨论】:
不可以,但是如果要根据其中一个属性的长度进行查询,可以使用类似于 SQL 的 length 函数:
select n from A order by length(name)
【讨论】:
David 的回答是正确的 - 您不能调用该函数 - 但在 EJBQL 中,查询应该如下所示:
select n from A n order by length(n.name)
【讨论】: