Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想通过使用类属性的函数订购查询。就像是:
@entity class A { private int id; private String name; public int StringLength() { return name.length(); } }
和句子类似:select n from A order by name.StringLength()。是否可以?
select n from A order by name.StringLength()
不,你不能,但是如果你想根据属性之一的长度进行查询,你可以使用类似于 SQL 的长度函数:
select n from A order by length(name)
David 的回答是正确的——你不能调用这个函数——但是在 EJBQL 中查询应该是这样的:
select n from A n order by length(n.name)