简体   繁体   中英

how to use hibernate second level cache for objects and collections

i have 3 classes

class A{
    List<B> child;
}

class B{
    List<C> child;
}

class C{
    String name;
}

in my application, class A will load by any request from users. am i should to use @Cache annotation above any classes? Should I use it above Lists or just put it above class A?

Hibernate has different regions for caching. If you want to cache a has-many collection, you can (ie the children for class B ), but then the class that makes up the collection needs to be Cached as well. Ultimately it comes down to what you need and what you want to cache.

So in your case you could cache any of the classes, and in addition, any of the List 's as well. Whether or not it makes sense to do so will probably require some load testing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM