Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Migrate the Hibernate Second-Level Caching With Hazelcast in Java 10

DZone's Guide to

Migrate the Hibernate Second-Level Caching With Hazelcast in Java 10

Click here to learn how to migrate the Hibernate second-level catching tool with the Hazelcast in Java 10.

· Java Zone ·
Free Resource

Verify, standardize, and correct the Big 4 + more– name, email, phone and global addresses – try our Data Quality APIs now at Melissa Developer Portal!

Technologies in any industry changes over time. The same goes for Java technologies. Recently, Oracle launched Java 10 on March 20, 2018. It was a paradigm shift in the Java project structure. Oracle Java has restructured all of its jar into different modules, i.e java.base, etc. Now, the module of a project can become modular in terms of JDK, as well. A certain number of packages are removed from JDK 10 i.e java.xml.binding. This means that the projects that get compiled and ran in older JDK will not get compiled in JDK 10. But, Oracle Java has provided features by which projects written in older JDK can be compiled and ran in JDK 10. For this reason, the project that is dependent on different frameworks or tools, which are not migrated to JDK 10, will not get compiled.

I have done the migration of project with the Hibernate second-level caching tool in Hazelcast to JDK 10 and executed some test cases to ensure it works properly. 

The maven-surefire-plugin of pom file of the project should be changed as follows: 

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.21.0</version>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>1.2.0</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.2.0</version>
</dependency>
</dependencies>
<configuration>
<argLine>
--illegal-access=deny
--add-modules=java.xml.bind
</argLine>
</configuration>
</plugin>


As I said earlier, java.xml.bind is being removed from JDK 10. So, the Hibernate project will not be compiled in JDK 10. In above code snippet, the tag <argLine> contains the additional arguments for the execution of JUnit 5 test cases successfully in JDK 10. 

The following dependency is required for Hibernate and Hazelcast configuration for caching

<!-- Hibernate Core -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.2.17.Final</version>
</dependency>

<!-- Hazelcast -->
<dependency>
<groupId>com.hazelcast</groupId>
<artifactId>hazelcast-hibernate52</artifactId>
<version>1.2.3</version>
</dependency>
<dependency>
<groupId>com.hazelcast</groupId>
<artifactId>hazelcast</artifactId>
<version>3.9.4</version>
</dependency>


Any other combination of Hibernate and Hazelcast versions may not compile or run properly for the project in JDK 10. So, by making the above changes in pom file for Hibernate with Hazelcast as caching in the project written in the older JDK, it will make the compilation and execution successful in JDK 10.

The source code is available at: https://github.com/aloktech/MigrateHibernateToJava10/tree/master/HibernateHazelcastCache.

Developers! Quickly and easily gain access to the tools and information you need! Explore, test and combine our data quality APIs at Melissa Developer Portal – home to tools that save time and boost revenue. 

Topics:
java 10 ,hibernate caching ,hazelcast ,maven 3.5.0 ,java ,tutorial

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}