Have any one had issues with using @DomainEvents with a Spring Data repository having @Cacheable decorated methods. It seems the domainEvents object don't get initialized when data comes from cache and hence give a NPE . This happens cause the transient variable not getting initialized when the data is coming from cache.
My caching repository is pretty simple looks like this, just the cache implementation I am using is based on Apache ignite. As a workaround currently I am not using domain events for cacheable methods, but I hope we can resolve this to get over the boilerplate and NPE issues
Affects: 1.13.8 (Ingalls SR8), 2.0.2 (Kay SR2)
The text was updated successfully, but these errors were encountered:
The caching interceptor is ordered before all other one, including the one publishing domain events. The entire scenario looks pretty weird as caching mutable objects is a bad idea in the first place as now all of a sudden, multiple threads will have access to instances that are usually only accessible in a single thread
Agree with your point about caching mutable entities .
But there could be a case where we do need to cache a search method or api in the repository , and this does break when the same data is say retrieved from cache ,modified and persisted.And subsequently domain events are fired .
This could be handled if I seperate the command and query as I have done now but we have a case where we do some intensive processing in memory and don't want to go every time to our persistence store .Also we have reverted to simple spring events right now .
Another approach we have done is using write behind in our apache ignite repositories and not using the @cacheable abstraction for our use case.