Using entity cache on multitenancy entities causes error.
stacktrace.txt (27.7 KB)
I have researched this myself and came up with conditions required to reproduce an error.
- Cached entity has a reference to another cached entity (ManyToMany, ManyToOne, doesn’t matter).
- Query view involves this reference. In this case, “Test parents” screen loads “child” attribute of “Parent” entity.
- Concrete child has not been cached yet. It seems the most interesting point. When the cached entity tries to load a reference to another cached entity, it understands that attribute in view is not loaded and EntityFetcher tries to fetch it, where the error actually occurs.
Better description will be the steps you can reproduce on attached project. It’s enough to run createDb task to make it work. It will create hsql db and test entities.
- Open “Test parents” screen without opening other ones (it’s important! Children entites must be not cached yet). The error will occur.
- Open “Test children” screen first, then open “Test parents” screen. It will be opened without errors.
- Open “Test parent edit” and there will be an error, since edit view has additional attribute “child2”.
- Open “Test child2s” screen, then open “Test parent edit” again. There will be no errors.
Error absence basically means child and child2 were already cached and there were no queries to the database. Therefore the problem I see here that EntityFetcher creates incorrect DB client session for eclipselink since it doesn’t contain “tenantId” property.