Monday, May 9, 2016

Error instantiating the Persistence Provider class org.hibernate.ejb.HibernatePersistence of the PersistenceUnit XXX: java.lang.ClassNotFoundException: org.hibernate.ejb.HibernatePersistence

I got this exception while trying to deploy an EJB ear that was created with maven to weblogic 12g :

Error instantiating the Persistence Provider class org.hibernate.ejb.HibernatePersistence of the PersistenceUnit XXX : java.lang.ClassNotFoundException: org.hibernate.ejb.HibernatePersistence

Note : I am having a certain problem preventing me from putting shared libraries in the lib folder in weblogic

I searched a lot and tried the following :

1- make sure that hibernate-entitymanager jar is included in the ear while deployment
2- put these entries in the persistence.xml file :
        <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
        <property name="hibernate.transaction.manager_lookup_class"
       value="org.hibernate.transaction.WeblogicTransactionManagerLookup" />
        <property name="hibernate.show_sql" value="true" />
3- put this in weblogic.xml :
         <prefer-application-packages>
            <package-name>antlr.*</package-name>
        </prefer-application-packages>
        <prefer-application-packages>
            <package-name>org.hibernate.*</package-name>
        </prefer-application-packages>

all these trials didn't solve the problem, I got another EJB ear that is working on weblogic and started the normal process of comparison between working and non-working ears and found the following :

4- the jar inside the ear that holds all the code has MANIFEST.MF inside its META-INF folder that has a Class-Path entry that points to the hibernate jars ..... I tried hard coding this entry and it worked.

5- Next I wanted to generate this entry automatically using maven, so I added the following entry to the pom.xml of the included jar's project :
           
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                        </manifest>

                        <manifestFile>src/main/resources/META-INF/MANIFEST.MF</manifestFile>
                    </archive>
                </configuration>
            </plugin>


 Now it's deploying fine







No comments:

Post a Comment