Which is better performance in hibernate native query or HQL

前端 未结 2 524
-上瘾入骨i
-上瘾入骨i 2020-12-15 08:52

In the server side code generally for better performance we should not use \"select * from table\" rather we should query the necessary column according to the need (Select

2条回答
  •  死守一世寂寞
    2020-12-15 09:11

    Entity queries (e.g. JPQL, HQL,Criteria API) are again rendered back to SQL queries, so it’s evident that running a native SQL query is going to be faster than running an entity query.

    However, if you set the query plan cache size right, then you could speed up entity queries so that they run as fast as SQL ones.

    But if you want to benefit from the dirty checking mechanism and issue UPDATE automatically from the modified entities, then an entity query is much more convenient. As long as the time difference between an entity query and an SQL query is insignificant (which most often is if you use database indexing and the entity query renders a very efficient SQL query), there’s nothing to worry about.

提交回复
热议问题