Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JPA native query and cache

Does native query in JPA (createNativeQuery) supports caching?
I am filling my own data transfer object because the sql query joins several tables and takes only several columns form them.

Regards

like image 769
darpet Avatar asked Jul 22 '10 07:07

darpet


People also ask

What is the difference between native query and JPA query?

In JPA, you can create a query using entityManager. createQuery() . You can look into API for more detail. Native query refers to actual sql queries (referring to actual database objects).

Does JPA have cache?

JPA has 2 levels of caching. The first level of caching is the persistence context. The JPA Entity Manager maintains a set of Managed Entities in the Persistence Context.

What is JPA native query?

Native query refers to actual sql queries (referring to actual database objects). These queries are the sql statements which can be directly executed in database using a database client. 2. Named query is the way you define your query by giving it a name.


1 Answers

This is possible but you must use an explicit .addScalar or .addEntity.

See also

  • Caching SQL query problem
  • Hibernate: Truly Understanding the Second-Level and Query Caches
like image 153
Pascal Thivent Avatar answered Oct 20 '22 18:10

Pascal Thivent