0

note: this Q is looking for a comparison of Hibernate named queries and ordinary session queries. Hibernate Criteria is of no concern within the context of this Q.

from what i know, named queries are those parsed once when the system starts up, and can be used from everywhere throughout the application. so - w/named queries, the query isn't parsed from scratch for each caller of that query and this is the major gain in named queries.

but then -

  • is there a difference between how Hibernate operates its caches for named- and ordinary-queries? if so- what is this?

  • is there any loss in turning ordinary Hibernate queries into named-queries?

i've had a discussion w/a colleague. he thinks that, before i should go turning ordinary queries into named queries, i should device some metrics and write tests just to prove how named-queries is performing better.

i think this-- generating metrics and writing tests just for the sake of measuring how/whether named queries perform better than ordinary queries is nothing but burning time into something useless. that's been shown already-- the reason of existence of named queries is just getting the query parsed. what data it's pulling/changing in DB is immaterial. and, Hibernate named queries is being used by many developers.

my Q is -

  • am i missing something in named queries that is relevant to this discussion?

  • opinions on how to handle this situation? the options i'm looking at are i.) drop doing anything at all-- let queries as is, ii.) just change named queries-- reverting if disliked wont have burned too much of my time iii.) do those tests-- if i would consider this as an option.

TIA.

ashley
  • 73
  • 1
  • 7

1 Answers1

0

Short answer - Use it if you can. But if you already have queries that are working fine with tests that cover its functionality, I wouldn't recommend that you go converting them.

Another SO post addressing this can be found here: Advantages of Named queries in hibernate?

Community
  • 1
  • 1
codedabbler
  • 1,231
  • 7
  • 13