Head.SmackOnTable();

Contains Nuts.

How to skin a live monkey by using just your teeth

without comments

… has nothing todo with what im about to tell you. No, really, it dosent. Although, its about the same – a quick how to on how to write SQL JOIN’s with nHibernates "super-shitty" HQL

Say heres your bog standard JOIN statement that you want to run:

SELECT * from MODEL INNER JOIN ModelClassTypeMap ON Model.Id = ModelClassTypeMap.ModelID  WHERE ClassTypeId=2 ORDER BY HighestNewRating DESC

You cant simply just rewrite that in HQL. HQL dosent use the "ON" directive. So you have to do multiple FROM statements, then tell it what you want to select. Sound easy? Welp, it isnt:

SELECT model FROM Model model, ModelClassTypeMap classTypeMap WHERE model.Id = classTypeMap.Model AND classTypeMap.ClassType = ? ORDER BY  classTypeMap.HighestNewRating DESC

To me this just seems retarded. You cant copy the sql that youv spent minutes perfecting, but you have to go and rewrite the whole thing so a 3 year old blind child whos been on cocaine for the last 6 months can understand it. Why not just do it so that you can reuse queries that you already have, instead of having to rewrite the whole way you write them? HQL is a poor mans SQL, its shoddy and flaky, and hardly documented.

Happiness is a warm gun.

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • DotNetKicks
  • DZone

Written by Monty

October 10th, 2007 at 10:55 am

Posted in .NET

Leave a Reply