While using the SimpleDelegatingSessionFactory with multiple databases and second level , there is potential for cache key conflicts.
This issue is also discussed here in more detail.
Example from the link above:
Database 1 with table "Employee" and record with an id of 5 would produce a cache key: NHibernate:Entities.EmployeeManagement.Employee:5@ 5
Database 2 with table "Employee" and record with an id of 5 would also produce a cache key: NHibernate:Entities.EmployeeManagement.Employee:5@ 5 <- Conflict
Setting the nhibernate property "cacheregionprefix" in the configuration would still leave the potential for a cache key conflict, as the configuration properties never change once read.
To remedy this, an update to the SimpleDelegatingSessionFactory to attempt to read the cache region prefix from the
logical thread context much like the connection string is currently read. The new cacheregionprefix is appended to the existing cacheregionprefix if present or sets the cacheregionprefix property before creating the SessionFactory related to the connection string.
This is the updated version of SimpleDelegatingSessionFactory.txt. I will request a pull on github if this is update doesn't need to be changed.