代码之家  ›  专栏  ›  技术社区  ›  Pablo Castilla

我可以通过一个未映射到数据库中的列的函数在EJBQL中排序吗?

  •  1
  • Pablo Castilla  · 技术社区  · 15 年前

    我希望通过使用类属性的函数来排序查询。类似:

    @entity
    class A
    {
    private int id;
    private String name;
    
    public int StringLength()
    {
    return name.length();
    }
    
    }
    

    句子是这样的: select n from A order by name.StringLength() . 有可能吗?

    2 回复  |  直到 13 年前
        1
  •  1
  •   David Rabinowitz    15 年前

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

    select n from A order by length(name)
    
        2
  •  0
  •   tputkonen    15 年前

    大卫的回答是正确的——你不能调用函数——但是在EJBQL中,查询应该如下所示:

    select n from A n order by length(n.name)
    
    推荐文章