Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is Hibernate second level cache useful for anything other than a "find by primary key" ?

From what I understand, the L2 cache is useful when finding an entity by using its primary key.

But is there any point using it for queries that are not based on the primary key? E.g.:

SELECT p FROM Person p WHERE p.age > 18 

If the query cache is NOT turned on, will the L2 cache be of any use at all?

like image 628
Pierre Duplouy Avatar asked Mar 16 '23 08:03

Pierre Duplouy


1 Answers

No, it won't be of any use in that case. The L2 cache is used when getting an entity by its ID, or when navigating through OneToOne and ManyToOne associations (which also causes an entity to be loaded by its ID, unless the referenced column is not the PK).

like image 97
JB Nizet Avatar answered Apr 27 '23 05:04

JB Nizet