|Force eclipselink to avoid pulling the same object on separate queries on the same entity [message #1800942]
||Thu, 10 January 2019 06:44
| Boris Okolodkov
Registered: January 2019
Maybe my question is dumb and I don't know what I'm talking about, but still. Is there any way to globally force eclipselink (persistence unit or entity manager configuration) to avoid fetched entities of the same type being pulled from L1 cache (if this is the case)?
Example: Let's say Ive got an entity annotated with @Cacheable(false) while having no additional entity manager properties except weaving turned off. So if I execute a findById() on the same id twice, the actual object in memory returned by these 2 calls is the same for me.
Moreover, this becomes a real brain-hurting problem when you have 2 tables connected by a foreign key (e.g. Employee -> Department). And first you fetch the parent object "Employee" containing it's child "Department" (by introspection). And later you fetch the same child object "Department" separately for some another purpose (like filling a select field to offer a possible change of the related parent property, i.e. move employee to another department). The problem here would be that the "Employee" will point to the very same object in memory "Department" as the separately fetched object (one of the objects in my select list). So basically I need to be aware all the time that when I change something inside my parent's child (through parent) I actually modify one of my select combo field objects.
The strange thing is that I do not get this behavior when running for ex. in WildFly (with integrated eclipselink 2.7) but when it's Spring Boot or some simple external container (same eclipselink version) it happens every time.
Also, anticipating some comments, I know that I'm fighting the very reason the cache was invented and my problem is more related to bad practices, but, in my particular case, it's an old and badly written system that I need to migrate to Spring Boot and I don't know what to do, except to rewrite it completely.
P.S. I can provide some code if my narrative does not explain the problem in full.
[Updated on: Thu, 10 January 2019 21:19]
Report message to a moderator
Powered by FUDForum
. Page generated in 0.02267 seconds