javax.persistence.PersistenceException : [PersistenceUnit: vodPersistenceUnit] 未找到类或包

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18054170/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 22:05:44  来源:igfitidea点击:

javax.persistence.PersistenceException : [PersistenceUnit: vodPersistenceUnit] class or package not found

javaspringhibernate

提问by Jean Reno

I got the following error :

我收到以下错误:

Error creating bean with name 'org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor#0' defined in class path resource [jpaDaoContext.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'vodEntityManagerFactory' defined in class path resource [jpaDaoContext.xml]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: vodPersistenceUnit] class or package not found

创建名为“org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor#0”的bean 在类路径资源[jpaDaoContext.xml] 中定义时出错:bean 初始化失败;嵌套异常是 org.springframework.beans.factory.BeanCreationException:在类路径资源 [jpaDaoContext.xml] 中定义名称为 'vodEntityManagerFactory' 的 bean 创建时出错:调用 init 方法失败;嵌套异常是 javax.persistence.PersistenceException: [PersistenceUnit: vodPersistenceUnit] 未找到类或包

I had a look on Google and I was told to choose transaction-type=RESOURCE_LOCAL but the settings were already that way. What is wrong with these settings :

我在 Google 上查看了一下,有人告诉我选择 transaction-type=RESOURCE_LOCAL,但设置已经这样了。这些设置有什么问题:

 <?xml version="1.0" encoding="UTF-8"?>
<persistence 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_1_0.xsd"
    version="1.0">

    <!-- transaction-type is RESOURCE_LOCAL or JTA -->
    <persistence-unit name="vodPersistenceUnit"
        transaction-type="RESOURCE_LOCAL">

        <class>mypackage.persistent.HistoriqueAction</class>
        <class>mypackage.persistent.ParametresTechniques</class>
        <class>mypackage.persistent.TicketType</class>
        <class>mypackage.persistent.TransactionType</class>
        <class>mypackage.persistent.StatutSession</class>
        <class>mypackage.persistent.Statistique</class>
        <class>mypackage.persistent.StatUser</class>

        <!-- Avoid to scan *.class and *.hbm.xml -->
        <exclude-unlisted-classes />


    </persistence-unit>

</persistence>

Regards

问候

采纳答案by Jean Reno

I fixed the issue. I had to comment these three lines in the file "persistence.xml" :

我解决了这个问题。我不得不在文件“persistence.xml”中注释这三行:

   <!--class>mypackage.persistent.TicketType</class>
    <class>mypackage.persistent.TransactionType</class>
    <class>mypackage.persistent.StatutSession</class--> 

For the moment i have no idea why it fixes the issue. It is really hard to debug this spring file.

目前我不知道为什么它解决了这个问题。调试这个spring文件真的很难。

回答by Luca Basso Ricci

You you haven't done that, put <property name="persistenceUnitName" value="vodPersistenceUnit" />in your jpaDaoContext.xml as property of your entityManagerFactory bean definition like:

你还没有这样做,把<property name="persistenceUnitName" value="vodPersistenceUnit" />你的 jpaDaoContext.xml 作为你的 entityManagerFactory bean 定义的属性,如:

<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
  <property name="persistenceUnitName" value="vodPersistenceUnit" />
  <property name="dataSource" ref="dataSource" />
  <property name="jpaVendorAdapter">...</property>
</bean>

回答by wavicle

If you had to comment out the "class" elements, it is likely that one of those classes is either not defined, or is not available in the classpath.

如果您必须注释掉“class”元素,则这些类之一可能未定义,或者在类路径中不可用。

I faced the same exact error, and it was resolved once the fully qualified names were all correct. Ideally, Hibernate should tell you what class is not found, but sadly it does not do it in this case.

我遇到了完全相同的错误,一旦完全限定名称都正确,它就解决了。理想情况下,Hibernate 应该告诉您未找到哪个类,但遗憾的是在这种情况下它没有这样做。

回答by Shahriar

I was running into this exception when trying to run a Spring Boot application in WebLogic 12.1.3 In the dependency tree I found out spring-tx was being included from one of the common project libraries. Our particular app only calls web service so there is no need for database access. So in the library dependency I added:

我在尝试在 WebLogic 12.1.3 中运行 Spring Boot 应用程序时遇到了这个异常 在依赖树中,我发现 spring-tx 被包含在一个公共项目库中。我们的特定应用程序仅调用 Web 服务,因此无需访问数据库。所以在库依赖项中我添加了:

<exclusions><exclusion> <groupId>org.springframework</groupId><artifactId>spring-tx</artifactId></exclusion></exclusions>