【问题标题】:Could I order in EJBQL by a function which is not mapped to a column in database?我可以通过未映射到数据库中列的函数在 EJBQL 中排序吗?
【发布时间】: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()。有可能吗?

【问题讨论】:

    标签: java jpa ejbql


    【解决方案1】:

    不可以,但是如果要根据其中一个属性的长度进行查询,可以使用类似于 SQL 的 length 函数:

    select n from A order by length(name)
    

    【讨论】:

      【解决方案2】:

      David 的回答是正确的 - 您不能调用该函数 - 但在 EJBQL 中,查询应该如下所示:

      select n from A n order by length(n.name)
      

      【讨论】:

        猜你喜欢
        • 2021-05-16
        • 1970-01-01
        • 2023-04-03
        • 1970-01-01
        • 2023-01-26
        • 1970-01-01
        • 2010-10-09
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多