简体   繁体   中英

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

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

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 :

 <?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

I fixed the issue. I had to comment these three lines in the file "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.

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.

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.

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

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

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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM