Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with @DomainEvents with a spring data repository having @cacheable decorated methods [DATACMNS-1247] #1690

Open
spring-projects-issues opened this issue Jan 20, 2018 · 3 comments
Assignees
Labels
status: feedback-provided type: bug

Comments

@spring-projects-issues
Copy link

@spring-projects-issues spring-projects-issues commented Jan 20, 2018

Gaurav Rawat opened DATACMNS-1247 and commented

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.

public class AbstractAggregateRoot<A extends AbstractAggregateRoot<A>> {
	private transient final @Transient List<Object> domainEvents = new ArrayList<>();

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)

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Jan 20, 2018

Oliver Drotbohm commented

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

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Jan 28, 2018

Gaurav Rawat commented

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.

@spring-projects-issues spring-projects-issues added status: waiting-for-feedback type: bug labels Dec 30, 2020
@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Jan 6, 2021

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

@spring-projects-issues spring-projects-issues added the status: feedback-reminder label Jan 6, 2021
@mp911de mp911de added status: feedback-provided and removed status: feedback-reminder status: waiting-for-feedback labels Jan 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: feedback-provided type: bug
Projects
None yet
Development

No branches or pull requests

3 participants