hibernate - Can JPA cache query every time we execute SELECT statement? -


for example, have following query(the implementation of jpa hibernate):

return em.createquery("select m.username member m", string.class)         .getresultlist(); 

i know jpa interpret query sql first time execute it, if second time? jpa interpret again? time consuming.

if change these queries namedquery, there noticeable performance improvement?

yes, query plan cached.

this flow:

  1. em.createquery(..)
  2. org.hibernate.internal.sessionimpl.createquery(string querystring)
  3. org.hibernate.internal.abstractsessionimpl.createquery(string querystring)
  4. org.hibernate.internal.sessionfactoryimpl.getqueryplancache().gethqlqueryplan( query, .. );

so query cached in session factory, once query translated going shared among future sessions.


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -