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:
- em.createquery(..)
- org.hibernate.internal.sessionimpl.createquery(string querystring)
- org.hibernate.internal.abstractsessionimpl.createquery(string querystring)
- org.hibernate.internal.sessionfactoryimpl.getqueryplancache().gethqlqueryplan( query, .. );
so query cached in session factory, once query translated going shared among future sessions.
Comments
Post a Comment