Hi Rob, I've encountered the same thing below and went with your option 1, as I was manually handling pagination and thus couldn't sort based on your option 2. >From what I infer, a field needs to be mapped in order for Hibernate to make use of it. I'm not aware of another way to do this.
On Dec 8, 2007 1:37 AM, Rob Hills <[EMAIL PROTECTED]> wrote: > Hi All, > > This is really a Hibernate column, but hopefully someone here will know > more about it than I do, which wouldn't be hard. > > I have a model class that includes an attribute "departureTime" of type > java.util.Date and the data contains both date and time information. In > my Dao class, I obtain a list of this object using Hibernate and I need > to sort it by the date component of the data (ie excluding the time). > > I've read the Hibernate documentation on HQL and AFAICT, HQL supports > expressions, but only in the Select part of the HQL. In the section on > "Order By", the documentation says that HQL will order a list "by any > property of a returned class or component". So, I created an @Transient > attribute "departureDate" + getter, that returned just the date part of > my data (in fact a string formatted to "yyyymmdd"), but that caused an > exception to be raised "could not resolve property departureDate". > > I tried searching to see if Hibernate supports Calculated columns, but > turned nothing up there. It seems to me there are only two options left: > > 1. Store the date string in its own column and sort on that; or > 2. Sort the list of objects myself in the Dao (or manager) after I've > retrieved them from Hibernate. > > Neither of these seems ideal to me. > > Does anyone know if there's a way to convince Hibernate to sort based on > an expression or convince it to create and use a calculated column? > > TIA, > > Rob Hills > Waikiki, Western Australia > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > -- Ealden Esto E. Escañan http://ealden.net
