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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.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
Spring java.lang.ClassNotFoundException:org.hibernate.ejb.HibernatePersistence_Spring_Hibernate_Jpa - Fatal编程技术网

Spring java.lang.ClassNotFoundException:org.hibernate.ejb.HibernatePersistence

Spring java.lang.ClassNotFoundException:org.hibernate.ejb.HibernatePersistence,spring,hibernate,jpa,Spring,Hibernate,Jpa,我正在尝试在以下环境中部署应用程序 JPA2.0 春季3.2.2 MySQL 5.6.11 到目前为止,我在application context.xml文件中的配置如下所示 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-in

我正在尝试在以下环境中部署应用程序

  • JPA2.0
  • 春季3.2.2
  • MySQL 5.6.11
到目前为止,我在
application context.xml
文件中的配置如下所示

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:p="http://www.springframework.org/schema/p"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
       http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
       http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">


    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
        <property name="persistenceUnitName" value="WebAppPU"/>
        <!--<property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                <property name="showSql" value="true"/>
                <property name="generateDdl" value="true"/>
                <property name="databasePlatform" value="org.hibernate.dialect.HSQLDialect"/>
            </bean>
        </property>-->
    </bean>

    <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/>

    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory"/>
    </bean>

    <tx:annotation-driven transaction-manager="transactionManager"/>

    <bean id="testDAOService" class="admin.dao.TestDAO"/>
</beans>

更新:

快速回复:(因为下面的答案没有直接说明异常的原因)

出现上述异常的原因(很可能)是,尽管我使用的是MySQL 5.x,但我在给定的XML文件中将
databasePlatform
错误地配置为
org.hibernate.dialen.hsqldialent

它实际上应该是
org.hibernate.dialogue.mysqldialogue
(或者版本限制/版本特定-
org.hibernate.dialogue.mysql5dialogue


免责声明:我不记得一年多后发生异常的确切原因,但最有可能(99.99%)是这种错误配置造成的。

当您使用Hibernate模板时,您需要使用Hibernate 3*

否则,您可以使用Hibernate4*

图书馆:

  • org.springframework.spring-orm
  • cglib
  • org.hibernate.hibernate-core
  • org.hibernate-c3p0
  • javaassist
pom.xml

<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>de.patrickgotthard</groupId>
    <artifactId>example</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            <version>3.1.1.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>cglib</groupId>
            <artifactId>cglib</artifactId>
            <version>2.2.2</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>4.1.1.Final</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-c3p0</artifactId>
            <version>4.1.1.Final</version>
        </dependency>
        <dependency>
            <groupId>javassist</groupId>
            <artifactId>javassist</artifactId>
            <version>3.12.1.GA</version>
        </dependency>
    </dependencies>
</project>

4.0.0
帕特里克哥达酒店
例子
1.0.0-SNAPSHOT
UTF-8
org.apache.maven.plugins
maven编译器插件
2.3.2
1.6
1.6
org.springframework
春季甲虫
3.1.1.1发布
cglib
cglib
2.2.2
org.hibernate
冬眠核心
4.1.1.最终版本
org.hibernate
hibernate-c3p0
4.1.1.最终版本
javassist
javassist
3.12.1.GA

Hibernate有一个可用java或其他java依赖关系管理器解决的问题。您似乎正在为使用Hibernate ORM适配器。

如果查看spring ORMmaven依赖项,您将看到它依赖于Hibernate entitymanager,该jar包含未找到的类


将这些依赖项添加到maven配置文件。

删除目录:

C:\Users\${user}.m2\repository\org\hibernate\

而再次安装这个系统对我来说是个好办法


HibernateException刚刚丢失,因此到hibernate entitymanager或maven repo的链接已损坏。

我不再使用hibernate,仍然需要这些jar文件吗?而
pom.xml
应该是不必要的,因为这不是一个maven项目。Hibernate就像EclipseLink或OpenJPA一样,是一个JPA提供者,这意味着您需要其中一个来使用JPA。我刚刚添加了这个pom.xml,以便您可以快速下载这些jar。我已经将这些jar文件添加到类路径
cglib-2.1.3.jar
hibernate-c3p0-4.2.0.CR1.jar
hibernate-core-4.2.0.CR1.jar
javassist-3.15.0-GA.jar
hibernate-entitymanager-4.2.0.CR1.jar
。这造成了。尝试在Google中搜索,但没有找到。我已经尝试添加了
hibernate-entitymanager-4.2.0.jar
,但没有解决问题。当我只添加
hibernate-entitymanager-4.2.0.jar
时,我得到了这个异常
java.lang.ClassNotFoundException:org.hibernate.hibernateeException
。我现在已经添加了这些jar文件,正如Templar提供的所示:
cglib-2.1.3.jar
hibernate-c3p0-4.2.0.CR1.jar
hibernate-core-4.2.0.CR1.jar
javassist-3.15.0-GA.jar
hibernate-entitymanager-4.2.0.CR1.jar
。这导致了。这是个麻烦,但是如果你看这里,你会发现你应该使用hibernate-core-3.2.2,因为4.2.0没有EntityNotFoundDelegate classI,我刚刚添加了hibernate 3.2.5中提供的所有jar文件(我之前使用过)我还得到了一个额外的异常
java.lang.IllegalStateException:PersistenceProvider[org.hibernate.ejb]。HibernatePersistence@1803041]未返回名为“WebAppPU”的EntityManagerFactory
。我的配置与回答中提到的相同。Tiny,我有一个类似的错误,不确定是什么导致了这个错误!对不起,我浏览了这篇文章,但我没有找到异常的原因。关于这个问题,我自己也记不清到底是什么变化使它起了作用。我没有在这里回答我自己,因为我没有太多的回应社区,因为我是非常新的这个领域在这个职位上的时间。
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
  <persistence-unit name="WebAppPU" transaction-type="RESOURCE_LOCAL">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <class>model.Test</class>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties>
      <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/social_networking?zeroDateTimeBehavior=convertToNull"/>
      <property name="javax.persistence.jdbc.password" value="root"/>
      <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
      <property name="javax.persistence.jdbc.user" value="root"/>
    </properties>
  </persistence-unit>
</persistence>
<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>de.patrickgotthard</groupId>
    <artifactId>example</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            <version>3.1.1.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>cglib</groupId>
            <artifactId>cglib</artifactId>
            <version>2.2.2</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>4.1.1.Final</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-c3p0</artifactId>
            <version>4.1.1.Final</version>
        </dependency>
        <dependency>
            <groupId>javassist</groupId>
            <artifactId>javassist</artifactId>
            <version>3.12.1.GA</version>
        </dependency>
    </dependencies>
</project>