On Dec 7, 2007 5:37 PM, 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".
Perhaps a small ray of light: the bit on Hibernate supporting functions in the order by clause is in the next section of the document 14.12: SQL functions and aggregate functions are allowed in the having and order byclauses, if supported by the underlying database (eg. not in MySQL). So could be done as long as you are not using MySql? Mike. > > > 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] > >
