Quentin
Quentin

Reputation: 3290

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

Upvotes: 6

Views: 1872

Answers (1)

Tomasz Nurkiewicz
Tomasz Nurkiewicz

Reputation: 340743

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:

Upvotes: 2

Related Questions