Skip to content

DATAJPA-1446 - Clear JpaMetamodel CACHE when application context is c… #301

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

Closed
wants to merge 1 commit into from

Conversation

Nowheresly
Copy link

@Nowheresly Nowheresly commented Oct 25, 2018

…losed.

  • You have read the Spring Data contribution guidelines.
  • There is a ticket in the bug tracker for the project in our JIRA.
  • You use the code formatters provided here and have them applied to your changes. Don’t submit any formatting related changes.
  • You submit test cases (unit or integration tests) that back your changes.
  • You added yourself as author in the headers of the classes you touched. Amend the date range in the Apache license header if needed. For new types, add the license header (copy from another file and set the current year only).

@@ -109,6 +112,11 @@ public boolean hasPersistentEntityFor(Class<?> type) {
return super.hasPersistentEntityFor(type) || models.isMetamodelManagedType(type);
}

@EventListener
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spring library components are not supposed to use @EventListener (it's a choice for application developers, but it's really inefficient, so not a good idea for libraries). You could put this in a @PreDestroy though, I expect (or DisposableBean probably better).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review! I just updated my PR to use a DisposableBean instead.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, implementing DisposableBean in class JpaMetamodelMappingContext was not triggering anything when application context is closed. Since JpaMetamodelMappingContextFactoryBean already implements DisposableBean, I decided to update my PR to clean the cache here instead.
This time, the cache is cleaned when applicationContext is closed.

@Nowheresly Nowheresly force-pushed the DATAJPA-1446 branch 2 times, most recently from 0eeb77f to d360807 Compare October 26, 2018 11:55
odrotbohm added a commit that referenced this pull request Oct 26, 2018
…losed.

We now register a dedicated Spring Bean to wipe the static cache in JpaMetamodel to avoid memory from leaking in scenarios where ApplicationContexts are started and closed very often (e.g. integration tests).

Heavily inspired by the work Sylvere Richard (@Nowheresly) has done in #301 but the key responsibility of wiping moved away from the MappingCOntext implementation.

Original pull request #301.
odrotbohm added a commit that referenced this pull request Oct 26, 2018
…losed.

We now register a dedicated Spring Bean to wipe the static cache in JpaMetamodel to avoid memory from leaking in scenarios where ApplicationContexts are started and closed very often (e.g. integration tests).

Heavily inspired by the work Sylvere Richard (@Nowheresly) has done in #301 but the key responsibility of wiping moved away from the MappingCOntext implementation.

Original pull request #301.
odrotbohm added a commit that referenced this pull request Oct 26, 2018
…losed.

We now register a dedicated Spring Bean to wipe the static cache in JpaMetamodel to avoid memory from leaking in scenarios where ApplicationContexts are started and closed very often (e.g. integration tests).

Heavily inspired by the work Sylvere Richard (@Nowheresly) has done in #301 but the key responsibility of wiping moved away from the MappingCOntext implementation.

Original pull request #301.
@odrotbohm
Copy link
Member

That's complete. I took a slightly different approach, see the ticket comment for details. Kept the credits in the classes around and attributed you in the commit message.

@odrotbohm odrotbohm closed this Oct 26, 2018
@Nowheresly Nowheresly deleted the DATAJPA-1446 branch October 26, 2018 14:57
stsypanov pushed a commit to stsypanov/spring-data-jpa that referenced this pull request Dec 13, 2019
…losed.

We now register a dedicated Spring Bean to wipe the static cache in JpaMetamodel to avoid memory from leaking in scenarios where ApplicationContexts are started and closed very often (e.g. integration tests).

Heavily inspired by the work Sylvere Richard (@Nowheresly) has done in spring-projects#301 but the key responsibility of wiping moved away from the MappingCOntext implementation.

Original pull request spring-projects#301.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants