• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Devaka Cooray
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
Bartenders:

Order by clause

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi.

I've got the following HQL:



Basically I want to convert the periodFrom to a String and put that into a list, but it should be sorted by the Date value that PeriodFrom is.

Thanks
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What type is period? If its a data can you not just order by it without the function?
 
Oddbjorn Lona
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Sturrock wrote:What type is period? If its a data can you not just order by it without the function?



Period is an alias for a converted periodFrom, so in other words a string.



 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, so you can't sort this chronologically since it is text. Another question: why do you convert to character data in the first place? Could you not just treat tge periodFrom property as a java.sql.Date?
 
Oddbjorn Lona
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Sturrock wrote:Ok, so you can't sort this chronologically since it is text. Another question: why do you convert to character data in the first place? Could you not just treat tge periodFrom property as a java.sql.Date?



Exactly.

I could probably treat the periodFrom as a date, and use a List<Date> instead of a List<String>. Probably would work.
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Its a general rule of thumb (well, one of mine anyway ) that if formatting logic appears in a SQL or HQL query something has gone wrong with the design somewhere. If you need to format stuff, do it after the query has returned results, assuming you don;t need the formatting to get the results in the first place, which with Dates you should not.
 
Oddbjorn Lona
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Sturrock wrote:Its a general rule of thumb (well, one of mine anyway ) that if formatting logic appears in a SQL or HQL query something has gone wrong with the design somewhere. If you need to format stuff, do it after the query has returned results, assuming you don;t need the formatting to get the results in the first place, which with Dates you should not.



hmm... good point.... i am coming from a plsql background so its a bit hard NOT to do as much formatting etc as possible in the sql
 
Mo-om! You're embarassing me! Can you just read a tiny ad like a normal person?
The new gardening playing cards kickstarter is now live!
https://www.kickstarter.com/projects/paulwheaton/garden-cards
reply
    Bookmark Topic Watch Topic
  • New Topic