简体   繁体   中英

Is there any way to set a single cache across all mapper files in Mybatis?

I am facing the following Mybatis cache problem.

Here is the use-case:

I have 3 Classes A , B and C and A class is having has- A relationship with B & C class. There are three mapper files a.xml , b.xml and c.xml for each classes to perform CRUD operations.

Retrieving Class A object ,which also includes B and C in it, by using join query written in a.xml file gives stale B and C object.

I can get rid of this issue by disabling cache in a.xml file, ie by commenting out the below line in a.xml file.

<cache />

But is there any better way to do this?

The cache tag is relevant to namespace. If all of your mappers have same namespace, then they should share a common cache.

See the documentation for cache-ref .

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