Issue
I am facing issue related to old version of dependency jpa2.0 mentioned in liberty server.xml file.
I want to use project's pom.xml hibernate-jpa-2.1-api dependency without removing liberty's jpa 2.0 (com.ibm.websphere.javaee.persistence.2.0_1.0.53.jar) dependency.
Error while deploying in liberty SIT environment:
Caused by: java.lang.NoSuchMethodError: javax/persistence/JoinColumn.foreignKey()Ljavax/persistence/ForeignKey; (loaded from file:/apps/waslb/sit/shared/websupporta/wlp/lib/../dev/api/spec/com.ibm.websphere.javaee.persistence.2.0_1.0.53.jar by org.eclipse.osgi.internal.loader.EquinoxClassLoader@69b35caa[com.ibm.websphere.javaee.persistence.2.0:1.0.53.cl210620210527-1900(id=117)]) called from class org.hibernate.cfg.AnnotationBinder (loaded from file:/apps/waslb/sit/shared/websupporta/wlp/usr/servers/websupporta11/apps/expanded/web-apps-esignservices-war.war/WEB-INF/lib/hibernate-core-4.3.11.Final.jar by com.ibm.ws.classloading.internal.AppClassLoader@40ad1256).
Below is the pom.xml file dependencies:
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>6.2.2.jre8</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.3.11.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.3.11.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate.common</groupId>
<artifactId>hibernate-commons-annotations</artifactId>
<version>4.0.5.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.1-api</artifactId>
<version>1.0.0.Final</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>1.2.0.RELEASE</version>
<exclusions>
<exclusion>
<artifactId>jcl-over-slf4j</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-asm</artifactId>
</exclusion>
</exclusions>
</dependency>
Solution
Method JoinColumn.foreignKey() was added in JPA2.2 library onwards, So below JPA2.2 version it's not available.
Issue resolved, After removing support of above method and dependencies version updated as mention below as hibernate version 4.2.15 is compatible with JPA 2.1
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.2.15.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.2.15.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.1-api</artifactId>
<version>1.0.0.Final</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>1.2.0.RELEASE</version>
</dependency>
Answered By - vinay chaudhary
Answer Checked By - Clifford M. (JavaFixing Volunteer)