NoSuchMethodError:javax.persistence.JoinColumn.foreignKey() [英] NoSuchMethodError: javax.persistence.JoinColumn.foreignKey()

查看:140
本文介绍了NoSuchMethodError:javax.persistence.JoinColumn.foreignKey()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在OpenShift(JBoss企业应用程序平台6)上部署我的应用程序,并且在标题中提到了NoSuchMethodError。所以我搜索了一下,发现一些文章或者线索提到了这个方法自JPA-API 2.1开始就可用。我发现Openshift所需的依赖包含JPA-API 2.0。我试图排除这种依赖,但它不起作用。有任何想法吗?

 < project xmlns =http://maven.apache.org/POM/ 4.0.0xmlns: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>
< version> 1.0< / version>
< name> christmasmarkets< / name>
< repositories>
< repository>
< id> eap< / id>
< url> http://maven.repository.redhat.com/techpreview/all< / url>
<发布>
< enabled> true< / enabled>
< / releases>
<快照>
< enabled> true< / enabled>
< / snapshots>
< / repository>
< repository>
< id> springsource-repo< / id>
< name> SpringSource存储库< /名称>
< url> http://repo.springsource.org/release< / url>
< / repository>
< / repositories>
< pluginRepositories>
< pluginRepository>
< id> eap< / id>
< url> http://maven.repository.redhat.com/techpreview/all< / url>
<发布>
< enabled> true< / enabled>
< / releases>
<快照>
< enabled> true< / enabled>
< / snapshots>
< / pluginRepository>
< / pluginRepositories>
<属性>
< 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-最终< /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>
<依赖关系>
< dependency>
< groupId> org.jboss.spec< / groupId>
< artifactId> jboss-javaee-6.0< / artifactId>
< version> 3.0.2.Final-redhat-4< / version>
< type> pom< / type>
< scope>提供< / scope>
<排除项>
<排除>
< groupId> org.hibernate.javax.persistence< / groupId>
< artifactId> hibernate-jpa-2.0-api< / artifactId>
< /排除>
< /排除>
< /依赖关系>
< dependency>
< groupId> org.springframework< / groupId>
< artifactId> spring-context< / artifactId>
< version> $ {spring.version}< / version>
< /依赖关系>
< dependency>
< groupId> org.springframework< / groupId>
< artifactId> spring-web< / artifactId>
< version> $ {spring.version}< / version>
< /依赖关系>

< dependency>
< groupId> org.springframework< / groupId>
< artifactId> spring-webmvc< / artifactId>
< version> $ {spring.version}< / version>
< /依赖关系>

< dependency>
< groupId> org.springframework< / groupId>
< artifactId> spring-tx< / artifactId>
< version> $ {spring.version}< / version>
< /依赖关系>
< dependency>
< groupId> org.springframework< / groupId>
< artifactId> spring-orm< / artifactId>
< version> $ {spring.version}< / version>
< /依赖关系>
< dependency>
< groupId> com.fasterxml.jackson.core< / groupId>
< artifactId> jackson-core< / artifactId>
< version> $ {jackson.version}< / version>
< /依赖关系>
< dependency>
< groupId> com.fasterxml.jackson.core< / groupId>
< artifactId> jackson-databind< / artifactId>
< version> $ {jackson.version}< / version>
< /依赖关系>
< dependency>
< groupId> com.fasterxml.jackson.core< / groupId>
< artifactId> jackson-annotations< / artifactId>
< version> $ {jackson.version}< / version>
< /依赖关系>
< dependency>
< groupId> org.hibernate< / groupId>
< artifactId> hibernate-entitymanager< / artifactId>
< version> $ {hibernate.version}< / version>
< /依赖关系>

< dependency>
< groupId> org.postgresql< / groupId>
< artifactId> postgresql< / artifactId>
< version> $ {postgre.version}< / version>
< /依赖关系>

< /依赖关系>
<个人资料>
<个人资料>
<! - 当在OpenShift中构建时,当
调用mvn时将使用'openshift'配置文件。 - >
<! - 使用此配置文件进行任何OpenShift特定定制,您的应用
将需要。 - >
<! - 默认情况下,将生成的存档放入部署
文件夹中。 - >
<! - http://maven.apache.org/guides/mini/guide-building-for-different-environments.html - >
< id> openshift< / id>
< build>
< finalName>圣诞市场< / finalName>
< plugins>
< plugin>
< artifactId> maven-war-plugin< / artifactId>
< version> 2.1.1< / version>
<配置>
< outputDirectory>部署< / outputDirectory>
< warName> ROOT< / warName>
< / configuration>
< / plugin>
< / plugins>
< / build>
< / profile>
< / profiles>


解决方案

这里的问题是由容器在运行时提供JPA 2.0 。排除 pom.xml 中提供的依赖项仅在编译时生效。为了解决这个问题,你必须在容器中配置类加载。


$ b OpenShift JavaEE 6支持基于JBoss AS 7.从
>

jboss-deployment-structure.xml是一个JBoss特定的部署
描述符,可以用来控制以细粒度
方式进行类加载。它应该放在META-INF
(或WEB-INF for web部署)的顶级部署中。它可以执行以下操作:

 防止添加自动依赖项
添加其他依赖项
...


所以你需要添加一个自定义 jboss-deployment-structure.xml 要排除自动添加 hibernate-jpa-2.0-api 的文件。



根据 OpenShift的文档

 < jboss-deployment-structure> 
< deployment>
<排除项>
< module name =javax.persistence.api/>
< /排除>
< / deployment>
< / jboss-deployment-structure>


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>

解决方案

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>

这篇关于NoSuchMethodError:javax.persistence.JoinColumn.foreignKey()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆