I a Spring project using MyBatis 3.5.6 and I have 2 mapper files:
BenefitsMapper.xml
<mapper namespace="Benefits">
<cache flushInterval="60000"/>
// ..... result maps, etc.
</mapper>
EmployeeMapper.xml
<mapper namespace="Employee">
<cache flushInterval="60000"/>
// ..... result maps, etc.
</mapper>
I just recently added a 3rd:
EmployeeBenefitsMapper.xml
<mapper namespace="Employee.Benefits">
<cache flushInterval="60000"/>
// ..... result maps, etc.
</mapper>
Everything builds and runs fine on Windows, but when I attempt to run on linux, I get an error that my context cannot be initialized because "Caches collection already contains value for Benefits". I'm wondering what the cause of this is. Somehow I'm getting a collision on the "Benefits" part of the namespaces, but it only occurs within Linux (using Ubuntu 20.02).
Unfortunately I do not have a replicable test scenario at this point.
Any help would be appreciated.
It is because the namespace of EmployeeBenefitsMapper.xml contains a dot 鈥媋nd the last segment of the namespace (short name) is the same as the namespace of another mapper (BenefitsMapper.xml).
Please see the 'NOTE' about namespace in the getting-started guide.
The error may occur when 'EmployeeBenefitsMapper.xml' is loaded before 'BenefitsMapper.xml'.
And load order could vary if you use mapper auto-scanning.
To avoid the problem, remove the dot in the namespace or replace it with underscore or something.
@harawata, that was it. Thank you.
That said, the behavior seems odd to me. A namespace is a unique thing. I'm not duplicating the namespace. It's counter intuitive IMO.
Regardless, thank you for the fix!
@ryno1234 ,
You're welcome!
A feature like 'short name' almost always makes things complicated.
And once it's released, it's virtually impossible to remove it as it breaks backward compatibility. :D
Anyway, I'm sorry about the trouble and am glad to know the problem is resolved.