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

Recipe to migrate the use of Ehcache 2.0 to 3.0 in Hibernate #2

Open
tkvangorder opened this issue Jan 7, 2023 · 4 comments
Open
Labels

Comments

@tkvangorder
Copy link
Contributor

Hibernate has deprecated the use of the ehcache 2.0 in favor of using jcache (with the ehcache 3.0 as the underlying implementation)

This recipe should:

  • Replace hibernate-ehcache dependency with hibernate-jcache
  • It should replace the hibernate.cache.region.factory_class property with jcache
  • It should add the following two properties :
<property name="hibernate.javax.cache.provider" value="org.ehcache.jsr107.EhcacheCachingProvider"/>
<property name="hibernate.javax.cache.uri" value="file:/META-INF/ehcache.xml"/>

And finally if the ehcache.xml file does not exist, it should create that file with a defaultCache entry:

<ehcache>
    <defaultCache maxEntriesLocalHeap="1000" eternal="false" timeToIdleSeconds="300" timeToLiveSeconds="600">
    </defaultCache>
</ehcache>
@knutwannheden
Copy link

This is for Hibernate 6.0, right?

@tkvangorder
Copy link
Contributor Author

Yes, this is for the move to Hibernate 6.0. I believe this approach could be applied to versions of Hibernate 5.4 and higher. I honestly have not worked with Hibernate in a very long time, but I ran across this as part of the work in openrewrite/rewrite-migrate-java#157 (The hibernate-ehcache no longer exists in Hibernate 6.)

@timtebeek timtebeek transferred this issue from openrewrite/rewrite-migrate-java Jun 9, 2023
@timtebeek timtebeek moved this to Recipes Wanted in OpenRewrite Jun 9, 2023
@bsmahi
Copy link

bsmahi commented Mar 26, 2024

@tkvangorder @knutwannheden @timtebeek In my view, Yes, hibernate-ehcache has been replaced with hibernate-jcache in Hibernate 6, this what have implemented in my recent project.

<dependency>
	<groupId>org.hibernate</groupId>
	<artifactId>hibernate-jcache</artifactId>
	<version>6.1.6.Final</version>
</dependency>

Hence the above dependency can be added for while migrating to Hibernate 6 and we have add the following entry in application.properties file

spring.jpa.properties.hibernate.cache.region.factory_class=org.hibernate.cache.jcache.internal.JCacheRegionFactory

So we can a recipe around it. Happy to work if the above solution is viable

Thanks,
Mahendra/Mahi

@timtebeek
Copy link
Contributor

Apologies for the late reply here; yes that seems like the correct step to take here, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Recipes Wanted
Development

No branches or pull requests

4 participants