Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When does hibernate use its first level cache ? how to log it?

Is there a simple way with hibernate log level to see when the first cache level is used or not ?

If I'm doing the following hql request : "from Document d left join fetch d.folder where d.id=2"; several time, in the same session, will the cache be used ?

Thanks

like image 627
Quentin Avatar asked Nov 05 '22 05:11

Quentin


1 Answers

Hibernate L1 cache stores entities by primary key. This means that if you load the same entity using load() or get() (I think this also applies to simple queries like: from Document d where d.id=2) it will be cached.

In your case the query is a bit more complicated and you will have to use L2. Unfortunately there is no logger indicating L1 activity (at least not documented) but seeing SQL queries shouls be enough.

See also:

  • Caching with Hibernate + Spring - some Questions!
like image 191
Tomasz Nurkiewicz Avatar answered Nov 10 '22 18:11

Tomasz Nurkiewicz