hi together,
i would like to know if it's possible to perform a "order by" on a "composite field" of a bean which is not stored in the db.
e.g "name" is a composite of "firstname + surname" (which are stored in db) but exists only in the bean.
(see the code below)
Bean
Code:
public class Person(){
String name;
String forename;
String surname;
//!!!Return the whole name! The order should be performed by this field!!!!
public String getName(){
return name;
}
public String getForename(){
return this.forename;
}
public String getSurname(){
return this.surname;
}
public void setName(){
this.name = getFirstName() + getSurname();
}
//Other setters
...
}
Mapping
Code:
//"name" is not mapped!
<class name="com.myapp.Person" table="person">
...
<property name="firstname" type="java.lang.String" column="firstname"/>
<property name="surname" type="java.lang.String" column="surname"/>
...
DAO
Code:
...
//Order result by "name"
Criteria criteria = getSession().createCriteria(Person.class);
criteria.addOrder("name", Order.asc);
...