-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: "order by" on composite bean field
PostPosted: Wed Mar 24, 2010 8:23 am 
Newbie

Joined: Fri Feb 29, 2008 3:44 am
Posts: 3
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);
    ...



Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.