Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how can i make sql queries database independent using Hibernate?

 
Abhishek Reddy
Ranch Hand
Posts: 259
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how can i make sql queries database independent using Hibernate?

iam storing date as string in database........for date conversion each database will follow some predefined methods

like wise there will be some other methods which serves the same purpose w.r.t database

how do i handle such cases in hibernate?
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which part are you worried about not being database independent?

Hibernate abstracts out the database thought the hibernate.cfg.xml file. So, you code Hibernate once, and you just change the entries in the xml file when you switch databases. Hibernate uses HQL, Hibernate Query Language, as opposed to SQL, so even there, you are buffered against a specific database SQL call.

>>for date conversion each database will follow some predefined methods

Well, this tends to be more the application/business logic problem. If every database is different, and it needs different logic, well, each database will need to be coded differently. But that's not a Hibernate or SQL issue, that's just an issue of the architect or application that it was designed in such a way that standard SQL, which has worked pretty good for almost every other application in the world, just doesn't cut it. Ok, that's perhaps a little over the top sarcastic, but I hope you see my point.

Perhaps a more mature question on my point would be to ask what this database specific task is? If we can factor that out, perhaps we can really get to the heart of the problem.

-Cameron McKenzie
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic