Open rameshsahydstgdn opened 5 months ago
Thanks for reporting it. I will try to replicate it according to your indications.
@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.
Thank you for the suggestion! Issue resolved by activating the second-level cache.
@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.
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