Using entity cache on multitenant entities causes error

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.

  1. Cached entity has a reference to another cached entity (ManyToMany, ManyToOne, doesn’t matter).
  2. Query view involves this reference. In this case, “Test parents” screen loads “child” attribute of “Parent” entity.
  3. 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.

  1. Open “Test parents” screen without opening other ones (it’s important! Children entites must be not cached yet). The error will occur.
  2. Open “Test children” screen first, then open “Test parents” screen. It will be opened without errors.
  3. Open “Test parent edit” and there will be an error, since edit view has additional attribute “child2”.
  4. 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.