0

I'm trying to deploy a spring-data-jpa,apache-cxf integrated project to Oracle Weblogic 12c (12.1.3) with below dependencies and getting below exception.

  • jdk :1.7
  • weblogic : 12c(12.1.3)
  • spring.version>4.1.0.RELEASE
  • spring.data.version>1.7.2.RELEASE
  • hibernate.version>4.3.11.Final

So far I did;

  • Tried to remove JPA 2.1 jar came from hibernate-entitymanager (didnt work,another exception thrown)
  • Tried to figure out spring-data-jpa,spring and hibernate dependency check(not succeeded)
  • Tried to give weblogic-applcation.xml for preferred-packages javax.persistence.* (doesn't change anything)
  • Deployed to 12.2.1 and it does work

I expect your valuable helps, thanks

Exception

<Warning> <HTTP> <BEA-101162> <User defined listener org.springframework.web.context.ContextLoaderListener failed: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in ServletContext resource [/WEB-INF/app-jpa-config.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: javax.persistence.JoinColumn.foreignKey()Ljavax/persistence/ForeignKey;org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in ServletContext resource [/WEB-INF/app-jpa-config.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: javax.persistence.JoinColumn.foreignKey()Ljavax/persistence/ForeignKey;
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1568)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:540)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:229)
Truncated. see log file for complete stacktrace 
Caused By:java.lang.NoSuchMethodError: javax.persistence.JoinColumn.foreignKey()Ljavax/persistence/ForeignKey;
at org.hibernate.cfg.AnnotationBinder.bindManyToOne(AnnotationBinder.java:2884)
at org.hibernate.cfg.AnnotationBinder.bindOneToOne(AnnotationBinder.java:3051)
at org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:1839)
at org.hibernate.cfg.AnnotationBinder.processIdPropertiesIfNotAlready(AnnotationBinder.java:963)
at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:796)
Truncated. see log file for complete stacktrace

mvn pom.xml

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <spring.version>4.1.0.RELEASE</spring.version>
    <spring.data.version>1.7.2.RELEASE</spring.data.version>
    <hibernate.version>4.3.11.Final</hibernate.version>
    <hibernate.validator.version>5.1.2.Final</hibernate.validator.version>
    <cxf.version>3.0.0</cxf.version>
    <log4j.version>1.2.17</log4j.version>
    <junit.version>4.12</junit.version>
</properties>
<dependencies>
    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-jpa</artifactId>
        <version>${spring.data.version}</version>
        <exclusions>
            <exclusion>
                <artifactId>spring-beans</artifactId>
                <groupId>org.springframework</groupId>
            </exclusion>
            <exclusion>
                <artifactId>spring-core</artifactId>
                <groupId>org.springframework</groupId>
            </exclusion>
            <exclusion>
                <artifactId>spring-aop</artifactId>
                <groupId>org.springframework</groupId>
            </exclusion>
            <exclusion>
                <artifactId>spring-context</artifactId>
                <groupId>org.springframework</groupId>
            </exclusion>
            <exclusion>
                <artifactId>spring-tx</artifactId>
                <groupId>org.springframework</groupId>
            </exclusion>
            <exclusion>
                <artifactId>spring-orm</artifactId>
                <groupId>org.springframework</groupId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-orm</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-tx</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-framework-bom</artifactId>
        <version>${spring.version}</version>
        <type>pom</type>
        <scope>import</scope>
    </dependency>
    <!-- Hibernate -->
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>${hibernate.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-transports-http</artifactId>
        <version>${cxf.version}</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-frontend-jaxws</artifactId>
        <version>${cxf.version}</version>
        <scope>compile</scope>
    </dependency>


    <!-- LOG -->
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>${log4j.version}</version>
    </dependency>
    <dependency>
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-classic</artifactId>
        <version>1.1.2</version>
        <exclusions>
            <exclusion>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-api</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.7.7</version>
    </dependency>
    <!-- TEST -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-test</artifactId>
        <version>${spring.version}</version>
    </dependency>

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>${junit.version}</version>
        <scope>test</scope>
    </dependency>

    <!-- Object2Object mapping -->
    <dependency>
        <groupId>net.sf.dozer</groupId>
        <artifactId>dozer</artifactId>
        <version>5.5.1</version>
    </dependency>


    <!-- ORACLE -->
    <dependency>
        <groupId>com.oracle</groupId>
        <artifactId>ojdbc6</artifactId>
        <version>11.2.0</version>
    </dependency>
</dependencies>
sabri
  • 15
  • 2
  • 6

1 Answers1

0

JoinColumn.foreignKey() was introduced with JPA 2.1 and it is implemented in Hibernate 4.3 so it could be that WebLogic is using it's own JPA JARs that have an older version. The fact that your code runs with no problem on Weblogic 12.2.1 would confirm this.
JPA 2.1 is part of Java EE 7 standard and it is supported from WebLogic 12.2.1 according to this

IMHO you were on the right track when trying to set preferred packages on WebLogic. Try going trough this tutorial to add the JPA 2.1 libraries to the WebLogic Server classpath.

iplese
  • 16
  • 3
  • Thank you, it worked. But I still didn't understand why weblogic ignored weblogic-application.xml provided preferred-package definition. Also jpa2.1.jar is under lib folder of the application. – sabri Dec 22 '15 at 13:56
  • @sabri did you manage to solve all the dependency issues for JPA and weblog 12.1? – cp5 Mar 27 '18 at 11:01
  • 1
    @Chrispie We did upgraded all the versions to; spring.version>4.2.8.RELEASE,spring.data.version>1.10.5.RELEASE,hibernate.version>4.3.11.Final,hibernate.validator.version>5.1.2.Final,cxf.version>3.1.6. And now it's working. And also JDK1.8.0_65. weblogic.xml does not have any extra preferred-package declarations. – sabri Mar 30 '18 at 07:38