Tag Archives: HQL

Hibernate Named Query


Hibernate Named Query

When working with Hibernate and Hibernate HQL, you will find yourself writing again and again the same tedious queries. Not only that, but most of the times these queries are scatterd throuout your code making it very hard too read and even harder to maintain. Hibernate Named Queries can provide a way of solving this problem. With Named queries you can define your customized queries written in SQL or HQL and then give them a name.

You can use that specific name any time you want to create and execute that query. Of course you have still the option of binding parameters etc. In some ways Named Queries are like stored procedures or like the public methods of a class. You can use a public method of a class to manipulate, read and write date to your class instance.

There are to basic ways you can declare named queries. One is using the .hbm.xml mapping file of you’re mapped class or by annotations.

So these are the tools we are going to use on a Windows 7 platform:

  • JDK 1.7
  • Maven 3.0.5
  • Hibernate 4.2.3.Final
  • MySQL JDBC driver 5.1.9
  • Eclipse 4.3 Kepler