0

My requirement is to get only the availability of records (not getting values). For this scenario,my problem is that what can be the better solution to improve performance between the JDBC query and the HQL Named query.

As I think,since named queries are loaded at the time of hibernate factories are loaded and therefore, it can be faster than jdbc.

Please not that This is not a normal HQL query, here I am asking about the Named Query.

Normal HQL and Named query can have different performance. Most of questions and answers are about normal HQL. My point here is the NAMED QUERY .

Débora
  • 5,816
  • 28
  • 99
  • 171
  • The only thing different is the avoidance of repeated parsing overhead, as you noted. How many queries per second are we talking here? – mabi Apr 02 '14 at 13:38
  • @AniketKulkarni I certainly I agree with the "Hibernate might not be a best solution when you want to squeeze every millisecond from your database." quote from your linked question. But I think the two problems are not quite the same - OP only wants to check existence, so there won't be any loading of rows/associations and performance of JDBC and Hibernate will probably be comparable. – mabi Apr 02 '14 at 13:41

2 Answers2

0

Hibernate is excellent . But most have problems with using criteria queries because they do not understand it should only be used with a small number of tables like 5 or less. If you are doing something in the enterprise level use HQL queries you have all the power of jdbc. Also the learning curve is high but once you learn nothing can compare.

iamVishal16
  • 1,780
  • 18
  • 40
0

I assume that your question is “which option you should choose between JDBC and Hibernate”.

First of all, With HQL you have your query ready with you and the query will not be going to be generated for every request. But In case of native SQL in hibernate , the query will be generated on demand if I’m not wrong.

Same with JDBC. If you use PreparedStatement , your query will be generated once in its life cycle. Almost both are same. By the way you have option to tell hibernate that you need the queries to be generated at start up of ORM engine or not. In JPA annotations you can use dynamic = true at @entity annotation.

If you already Hibernate/JPA infrastructure in your project make use of it else go with plain vanilla JDBC option.

Balaji Reddy
  • 5,576
  • 3
  • 36
  • 47