Search code examples
javahibernateormhqlresultset

What are the benefits of HQL?


The benefits of an ORM are that I can map database tables to Java objects. If I use HQL to write custom statements then what's the point? I may as well write normal SQL queries and use ResultSets?


Solution

  • Well, basically because sometimes it is impossible (or very hard) to write queries using the other alternatives. Then you need to fallback to the HQL alternative.

    HQL has, as disadvantage, the fact that you write strings with it. So it is highly recommended other strategies. But, sometimes, it is the fastest way to implement it.

    I would also say for you to read this post, which was extensively discussed about HQL already: JPA and Hibernate - Criteria vs. JPQL or HQL