• 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:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Hibernate - compound column?

 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm just starting out with hibernate, so hopefully this is a dumb question. Using SQL, I do things like this all the time because our DB seperates dates into 3 columns:



how can I do something similar in hibernate and use it in a query?

another question: Should I bother learning HQL? I'm comfortable with SQL already.

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
All you are doing with an ORM is mapping entities to POJOs. If you have an entity which defines a date as three fields, rather than using a DATE or TIMESTAMP (I can think of no good reason for doing this, but I'll assume you have one) then these values just get mapped to properties in a POJO. So rather than concatinating them in SQL, I'd include a derived property in your POJO which is these three properties concatinated.


Should I bother learning HQL? I'm comfortable with SQL already.


Its a good idea. Remember that SQL isn't truely portable. It might be called a standard, but its been variously implemented and extended on different DB platforms. The digits function you are using here for example isn't SQL, its Transact SQL (correct me if I'm wrong - I haven't checked).

One of the reasons for using an ORM is to free yourself up from DB dependencies - unfortunately if you rely on SQL rather then HQL you'll have to be very careful you don't introduce code which will generate SQLExceptions when you deploy it with a DB platform other than the one you developed on. And HQL is not exactly complicated anyway.
 
Clifford Adams
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply.

That's a good reason to larn HQL. Our backend is currently DB2 on AS400, but will be moving to Oracle in the next few years. When the change happens, all I would have to do is change my dialect setting, right?

FYI - I curse the designers of this DB every day. There is no good reason for the split dates, AFAIK.
 
It's a pleasure to see superheros taking such an interest in science. And this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic