tags:

views:

136

answers:

2

Hello everyone,

I would like to order a query by a function which uses properties of the class. Something like:

@entity class A { private int id; private String name;

public int StringLength() { return name.length(); }

}

And the sentence something like: "select n from A order by name.StringLength()". Is it possible?

Thanks in advance.

+1  A: 

No you can't, but if you want to query based on the length of one of the property you can use the length function similar to SQL:

select n from A order by length(name)
David Rabinowitz
A: 

David's answer was right - you cannot call the function - but in EJBQL the query should look something like this:

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