Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JPA/Hibernate java.lang.NoSuchMethodError_Java_Hibernate_Maven_Jpa - Fatal编程技术网

JPA/Hibernate java.lang.NoSuchMethodError

JPA/Hibernate java.lang.NoSuchMethodError,java,hibernate,maven,jpa,Java,Hibernate,Maven,Jpa,错误消息 2015年10月20日晚上10:56:33 org.hibernate.dialen.dialen信息: HH000400:使用方言:org.hibernate.dialogue.postgresql9dialogue 2015年10月20日晚上10:56:33 org.hibernate.engine.jdbc.internal.LobCreatorBuilder UseContextAllobCreation信息:HH000424:禁用上下文LOB 创建为createClob()方

错误消息

2015年10月20日晚上10:56:33 org.hibernate.dialen.dialen信息: HH000400:使用方言:org.hibernate.dialogue.postgresql9dialogue 2015年10月20日晚上10:56:33 org.hibernate.engine.jdbc.internal.LobCreatorBuilder UseContextAllobCreation信息:HH000424:禁用上下文LOB 创建为createClob()方法引发错误: 线程“main”中的java.lang.reflect.InvocationTargetException异常 java.lang.NoSuchMethodError: javax.persistence.JoinColumn.foreignKey()Ljavax/persistence/foreignKey

我知道是这样的,但正如大多数人所说的,他们要求确保我使用的是Hibernate4.3+和JPA2.1+。我相信我正在使用这两种方法:

这是我的persistence.xml

<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
  <persistence-unit name="web" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties>
      <property name="javax.persistence.jdbc.url" value="jdbc:postgresql://localhost:5432/web"/>
      <property name="javax.persistence.jdbc.user" value="postgresUser"/>
      <property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver"/>
      <property name="javax.persistence.jdbc.password" value="admin"/>
      <property name="hibernate.cache.provider_class" value="org.hibernate.cache.NoCacheProvider"/>
      <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
      <property name="hibernate.ejb.entitymanager_factory_name" value="web" />
    </properties>
  </persistence-unit>
</persistence>
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>edu.utfpr</groupId>
<artifactId>ProjetoWeb</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>

<name>ProjetoWeb</name>

<properties>
    <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>4.3.1.Final</version>
    </dependency>
    <dependency>
        <groupId>org.torpedoquery</groupId>
        <artifactId>org.torpedoquery</artifactId>
        <version>1.7.0</version>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</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.hibernate</groupId>
        <artifactId>hibernate-jpamodelgen</artifactId>
        <version>5.0.2.Final</version>
    </dependency>
    <dependency>
        <groupId>org.postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <version>9.2-1002-jdbc4</version>
    </dependency>
    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-web-api</artifactId>
        <version>7.0</version>
        <scope>provided</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
                <compilerArguments>
                    <endorseddirs>${endorsed.dir}</endorseddirs>
                </compilerArguments>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.3</version>
            <configuration>
                <failOnMissingWebXml>false</failOnMissingWebXml>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>2.6</version>
            <executions>
                <execution>
                    <phase>validate</phase>
                    <goals>
                        <goal>copy</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${endorsed.dir}</outputDirectory>
                        <silent>true</silent>
                        <artifactItems>
                            <artifactItem>
                                <groupId>javax</groupId>
                                <artifactId>javaee-endorsed-api</artifactId>
                                <version>7.0</version>
                                <type>jar</type>
                            </artifactItem>
                        </artifactItems>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
</project>
我可以做些什么来部署它?


很抱歉,无法将pom.xml/persistence.xml简化为更通用的格式,因为我不确定错误在哪里。

这通常意味着您使用的库版本与您真正依赖的库版本不兼容。请检查javax.persistence.JoinColumn.foreignKey()库或使用此库的人的版本,以确保您使用的是正确的版本

正如双方所说,这肯定是一个依赖性问题。但是,我相信,对于一个缺乏经验的人来说,很难判断什么应该匹配/可能是错误的

那么,下面是一个如何检查这个的方法

pom.xml
中的相关数据为:

    <artifactId>hibernate-entitymanager</artifactId>
    <version>4.3.1.Final</version>
    (...)
    <artifactId>hibernate-jpa-2.1-api</artifactId>
    <version>1.0.0.Final</version>
    (...)
    <artifactId>hibernate-jpamodelgen</artifactId>
    <version>5.0.2.Final</version>
hibernate实体管理器
4.3.1.最终版本
(...)
hibernate-jpa-2.1-api
1.0.0.1决赛
(...)
冬眠
5.0.2.2最终版本
正如用户所说,hibernate需要是4.3或更高版本,这是正确的。但是,它应该使用相同版本的hibernate和jpamodelgen

hibernate entitymanagerhibernate jpamodelgen应该具有相同的编号。就这样吧:


4.3.1
5.0.2

如何检查此版本?是否有println或我可以做的事情?这是对pom.xml文件的依赖关系。首先,您需要找出哪个库正在使用javax.persistence.JoinColumn.foreignKey()方法。然后检查所需的版本。如果您错误地使用了这些版本,您将在运行时遇到这种错误。这肯定是一个依赖性问题。还要查找重复的依赖项并尝试消除它们。i、 e.两个不同版本的jpa api,等等。我正在使用Jboss-eap-6.4如何防止Jboss加载旧版本的javax.persistence,我既不使用提供的范围,也不使用maven Dependency中的编译范围您的类路径中有jpa api的早期版本(没有该方法)。这就是所有要说的,从信息中不言而喻,谢谢。改变你说的话真的解决了这个问题。
    <artifactId>hibernate-entitymanager</artifactId>
    <version>4.3.1.Final</version>
    (...)
    <artifactId>hibernate-jpa-2.1-api</artifactId>
    <version>1.0.0.Final</version>
    (...)
    <artifactId>hibernate-jpamodelgen</artifactId>
    <version>5.0.2.Final</version>