Saturday, February 13, 2010

Why Did They Introducing HQL (Hibernate Query Language)

It is possible to use native SQL queries directly with a Hibernate-based persistence layer, it is more efficient to use HQL instead.

  • HQL allows representing SQL queries in object-oriented terms—by using objects and properties of objects.

  • Instead of returning plain data, HQL queries return the query result(s) in the form of object(s)/tuples of object(s) that are ready to be accessed, operated upon, and manipulated programmatically. This approach does away with the routine task of creating and populating objects from scratch with the "resultset" retrieved from database queried.

  • HQL fully supports polymorphic queries. That is, along with the object to be returned as a query result, all child objects (objects of subclasses) of the given object shall be returned.

  • HQL is easy to learn and implement, as its syntax and features are very similar to SQL.

  • HQL contains many advance features such as pagination, fetch join with dynamic profiling, and so forth, as compared to SQL.

  • HQL facilitates writing database-type independent queries that are converted to the native SQL dialect of the underlying database at runtime. This approach helps tap the extra features the native SQL query provides, without using a non-standard native SQL query.
  • No comments:

    Post a Comment