Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NoSuchMethodError: javax.persistence.JoinColumn.foreignKey()

I'm trying to deploy my application on OpenShift (JBoss Enterprise Application Platform 6) and I get the NoSuchMethodError mentioned in the title. So I googled the whole thing and found a few articles or threads that mentioned that this Method is available since JPA-API 2.1. I found out that a dependency that is necessary for Openshift contains the JPA-API 2.0. I tried to exclude this dependency but it does not work. Any ideas? Please find the pom.xml below.

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>christmasmarkets</groupId>
<artifactId>christmasmarkets</artifactId>
<packaging>war</packaging>
<version>1.0</version>
<name>christmasmarkets</name>
<repositories>
    <repository>
        <id>eap</id>
        <url>http://maven.repository.redhat.com/techpreview/all</url>
        <releases>
            <enabled>true</enabled>
        </releases>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
    <repository>
        <id>springsource-repo</id>
        <name>SpringSource Repository</name>
        <url>http://repo.springsource.org/release</url>
    </repository>
</repositories>
<pluginRepositories>
    <pluginRepository>
        <id>eap</id>
        <url>http://maven.repository.redhat.com/techpreview/all</url>
        <releases>
            <enabled>true</enabled>
        </releases>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </pluginRepository>
</pluginRepositories>
<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.6</maven.compiler.source>
    <maven.compiler.target>1.6</maven.compiler.target>
    <spring.version>4.1.2.RELEASE</spring.version>
    <hibernate.version>4.3.7.Final</hibernate.version>
    <hibernate-annotations.version>3.5.6-Final</hibernate-annotations.version>
    <hibernate-commons-annotations.version>3.2.0.Final</hibernate-commons-annotations.version>
    <jackson.version>2.2.3</jackson.version>
    <postgre.version>9.3-1102-jdbc41</postgre.version>
</properties>
<dependencies>
    <dependency>
        <groupId>org.jboss.spec</groupId>
        <artifactId>jboss-javaee-6.0</artifactId>
        <version>3.0.2.Final-redhat-4</version>
        <type>pom</type>
        <scope>provided</scope>
        <exclusions>
            <exclusion>
                <groupId>org.hibernate.javax.persistence</groupId>
                <artifactId>hibernate-jpa-2.0-api</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>${spring.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</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-orm</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-core</artifactId>
        <version>${jackson.version}</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <version>${jackson.version}</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-annotations</artifactId>
        <version>${jackson.version}</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>${hibernate.version}</version>
    </dependency>

    <dependency>
        <groupId>org.postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <version>${postgre.version}</version>
    </dependency>

</dependencies>
<profiles>
    <profile>
        <!-- When built in OpenShift the 'openshift' profile will be used when 
            invoking mvn. -->
        <!-- Use this profile for any OpenShift specific customization your app 
            will need. -->
        <!-- By default that is to put the resulting archive into the 'deployments' 
            folder. -->
        <!-- http://maven.apache.org/guides/mini/guide-building-for-different-environments.html -->
        <id>openshift</id>
        <build>
            <finalName>christmasmarkets</finalName>
            <plugins>
                <plugin>
                    <artifactId>maven-war-plugin</artifactId>
                    <version>2.1.1</version>
                    <configuration>
                        <outputDirectory>deployments</outputDirectory>
                        <warName>ROOT</warName>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>

like image 426
Patrick Zinner Avatar asked May 16 '26 12:05

Patrick Zinner


1 Answers

The problem here is that JPA 2.0 is provided at runtime by the container. Exclusion of the provided dependency in pom.xml has effect only at compile time. To solve this problem you must configure class loading in the container.

OpenShift JavaEE 6 support is based on JBoss AS 7. From Class Loading in AS7 documentation:

jboss-deployment-structure.xml is a JBoss specific deployment descriptor that can be used to control class loading in a fine grained manner. It should be placed in the top level deployment, in META-INF (or WEB-INF for web deployments). It can do the following:

   Prevent automatic dependencies from being added
   Add additional dependencies
   ...

So what you need is to add a custom jboss-deployment-structure.xml file to exclude hibernate-jpa-2.0-api from being added automatically.

Based on OpenShift's documentation:

<jboss-deployment-structure>
   <deployment>
      <exclusions>
         <module name="javax.persistence.api" />
      </exclusions>
   </deployment>
</jboss-deployment-structure>
like image 114
Alex Filatov Avatar answered May 19 '26 02:05

Alex Filatov