Jean Reno
Jean Reno

Reputation: 163

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

Upvotes: 4

Views: 20011

Answers (5)

WesternGun
WesternGun

Reputation: 12738

Specify the correct qualified names of the classes you need in <class> part, and also, if it's a test and the tables are created ad-hoc, make sure the table itself is present

Upvotes: 0

Shahriar
Shahriar

Reputation: 303

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>

Upvotes: 0

wavicle
wavicle

Reputation: 1304

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.

Upvotes: 3

Jean Reno
Jean Reno

Reputation: 163

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.

Upvotes: 6

Luca Basso Ricci
Luca Basso Ricci

Reputation: 18403

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>

Upvotes: 1

Related Questions