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

NaturalIdCacheEvent is triggered even when having the @NaturalIdCache in place #245

Open
rameshsahydstgdn opened this issue Jun 16, 2024 · 4 comments

Comments

@rameshsahydstgdn
Copy link

Issue Summary:

The Hypersistence Optimizer is suggesting to add the @NaturalIdCache annotation to entities that already have it, specifically when using natural identifiers. This recommendation appears even when the annotation is correctly applied at the entity level.

Steps to Reproduce:

Define an entity in Hibernate with natural identifiers (@naturalid).
Apply the @NaturalIdCache annotation to the entity class.
Run the Hypersistence Optimizer or integrate it into a Spring Boot application.
Observe the generated NaturalIdCacheEvent warning.

Expected Behavior:

The Hypersistence Optimizer should recognize that @NaturalIdCache is already present on the entity and not suggest adding it again, assuming it's correctly placed.

Actual Behavior:

The optimizer suggests adding @NaturalIdCache even when it is already used in the entity definition. This can lead to confusion and unnecessary recommendations in the optimization report.

Environment:

Hypersistence Optimizer version: 2.9.0, classifier: jakarta
Hibernate version: 6.5.2.Final
Spring Boot version: 3.3.0
Database: postgresql:16

@vladmihalcea
Copy link
Owner

Thanks for reporting it. I will try to replicate it according to your indications.

vladmihalcea added a commit that referenced this issue Jun 17, 2024
@vladmihalcea
Copy link
Owner

@rameshsahydstgdn I build this example to replicate the issue.

I assume you added the @NaturalIdCache annotation without activating the second-level cache, and that's why you got the NaturalIdCacheEvent.

If you activate the second-level cache via the spring.jpa.properties.hibernate.cache.region.factory_class property and the Maven dependency (e.g., Ehcache), then the event is no longer triggered, as proven by the test case.

So, in this case, I could change the message of the NaturalIdCache event to make it easier for devs to find out that the cache annotations themselves do nothing in the absence of the second-level cache.

@vladmihalcea vladmihalcea changed the title NaturalIdCacheEvent suggests adding @NaturalIdCache even when already added NaturalIdCacheEvent is triggered even when having the @NaturalIdCache in place Jun 17, 2024
@rameshsahydstgdn
Copy link
Author

Thank you for the suggestion! Issue resolved by activating the second-level cache.

@vladmihalcea
Copy link
Owner

vladmihalcea commented Jun 17, 2024

@rameshsahydstgdn I will reopen it in order to investigate a way to change the message based on whether the second-level cache is active or not.

@vladmihalcea vladmihalcea reopened this Jun 17, 2024
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

No branches or pull requests

2 participants