Named Query Or Native Query or Query Which one is better in performance point of view?

前端 未结 5 641
滥情空心
滥情空心 2021-02-05 12:49

Which one is better among following(EJB 3 JPA)

//Query

a). getEntityManager().createQuery(\"select o from User o\");

//Named Query where

5条回答
  •  伪装坚强ぢ
    2021-02-05 13:35

    Native SQL is not necessarily faster than Hibernate/JPA Query. Hibernate/JPA Query finally also is translated into SQL. In some cases it can happen Hibernate/JPA does not generate the most efficient statements, so then native SQL can be faster - but with native SQL your application loses the portability from one database to another, so normally is better to tune the Hibernate/JPA Query mapping and the HQL statement to generate more efficient SQL statements. On the other side with native SQL you're missing the Hibernate cache - as a consequence in some cases native SQL can be slower than Hibernate/JPA Query.

    I am not with performance, in most cases for the performance it is irrelevant if your load all columns or only the needed columns. In database access the time is lost when searching the row, and not when transferring the data into your application. When you read only the necessary columns.

提交回复
热议问题