• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

what's the syntax differnece between hibernate hql and sql?

 
Tony Smith
Ranch Hand
Posts: 229
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what's the syntax differnece between hibernate hql and sql? Is sql 100% native sql which means you should be able to paste the sql code into mysql query browser and it should work?
 
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
Yup, if you paste SQL into the MySQL query browser, that should run. When I'm having trouble with my queries, I often take the SQL generated by Hibernate, stuff it into the MySQL query browser, and see what happens. Sometimes, fiddling with the SQL can help me see what I've done wrong in my HQL or Criteria queries.

HQL is Hibernate based, and Hiberante is based on Java Objects. So, I can have one Java object that maps to three database tables. Selecting * from that class would generate SQL that queries all three databases. So, in just that one scenario, you can see that the HQL and SQL would be very, very different.

In many applications, the database tables and Java objects mirror each other, so sometimes the SQL and HQL can look very, very similar. But don't let this lull you into thinking they are the same. They are two very different monsters.

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