0

I got below point everywhere which advocates the use of named queries

Often times, developer like to put HQL string literals scatter all over the Java code, this method is hard to maintaine and look ugly.

I am not getting how named queries avoid scattering of HQL strings. The only difference is that if we dont use named queries, queries are decalred inside daos(say as constants) but with named queries they are declared under entity objects(using annotation). But still HQL query strings are scattered in both the techniques. How named queries makes the code easy to maintain and readable?

user3198603
  • 5,528
  • 13
  • 65
  • 125
  • because you can identify and group your **named** queries using nice names :). why do we use meaningful variable names? – Adi Dec 15 '14 at 11:55
  • But you can provide nice names also as constants in dao – user3198603 Dec 15 '14 at 12:01
  • NamedQueries can improve performance, because the ORM will not need to parse and compile the query from scratch each time it's used. Also it can do application start-up time validation, which is impossibl ewith ordinary string constants. And last but not least - you get IDE support with @NamedQueries, at least in eclipse – Svetlin Zarev Dec 15 '14 at 12:03
  • well. there are many other advantages. like pre-compilation of named queries. see [this](http://stackoverflow.com/questions/7769447/advantages-of-named-queries-in-hibernate) thread for more information. I was stating just obvious one. – Adi Dec 15 '14 at 12:03

0 Answers0