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

前端 未结 5 643
滥情空心
滥情空心 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:39

    Named queries are the same as queries. They are named only to let them be reusable + they can be declared in various places eg. in class mappings, conf files etc(so you can change query without changing actaul code)

    Native queries are just native queries right, you have to do all the things that JPA Queries do for you eg. Binding and quoting values etc. + they use DBMP independent syntax (JPQL in your case) so changing database system (lets saq from MySQL to Postgresql or H2) will require less work as it does not (not always) require to rewrite native queries.

提交回复
热议问题