-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 10 posts ] 
Author Message
 Post subject: No Persistence provider for EntityManager in tomcat
PostPosted: Sat Mar 04, 2006 12:47 pm 
Newbie

Joined: Sat Mar 04, 2006 12:17 pm
Posts: 4
I get "javax.persistence.PersistenceException: No Persistence provider for EntityManager named fadao" when I do "emf = Persistence.createEntityManagerFactory("fadao");" out of a tomcat 5 Servlet (JSP to be exactly). No Applicationserver is used, just J2SE.
However, with a "this.getClass().getClassLoader().getResources("META-INF/persistence.xml");" I can retrieve the URL of the persistence.xml file, but not with "ClassLoader.getSystemClassLoader().getResources("META-INF/persistence.xml");"

The persistence.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!-- example of reference to a cfg.xml file -->
<persistence>
<persistence-unit name="fadao" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.ejb.cfgfile" value="hibernate.cfg.xml"/>
</properties>
</persistence-unit>
</persistence>

Classloader problems is just a guess from me.

Thanks for any help!


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 12, 2006 4:40 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
what is your war structure?

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 13, 2006 1:33 pm 
Newbie

Joined: Sat Mar 04, 2006 12:17 pm
Posts: 4
Thanks for answering.

All the hibernate/persistence related things is separated from the web stuff in a .jar library under WEB-INF/lib. The persistence.xml is in this jar in the META-INF directory.

Thanks, Peter


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 14, 2006 8:57 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
hibernate-entitymanager is in the WEB-INF/lib, then.
What I do is to use the thread context classloader. So Tomcat might not set it properly, but that's weird.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 14, 2006 3:34 pm 
Newbie

Joined: Sat Mar 04, 2006 12:17 pm
Posts: 4
Emmanuel,

solved it, Classloader issues were not the reason (Thread().currendThread().getContextClassLoader() showed the resource), but missing lib in the classpath (at the end I don't know which).

Many thanks for your help,

Peter


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 05, 2006 4:36 pm 
Newbie

Joined: Mon Dec 12, 2005 6:00 pm
Posts: 11
I am having a very similar problem with tomcat. Do you have any more info on your solution. I have persistence.xml in WEB-INF/classes/META-INF. I tried accessing this file through various class loader shenanigans.

this.getClass().getClassLoader().getResource("META-INF/persistence.xml")
works

ClassLoader.getSystemClassLoader().getResource("META-INF/persistence.xml")
doesn't work

Thread.currentThread().getContextClassLoader().getResource("META-INF/persistence.xml")
works

I added antlr, asm, asm-attrs, c3p0, cglib, commons-collections, dom4j, ehcache and jta jars to my web app. I already had commons-logging and log4j.

I still get the "javax.persistence.PersistenceException: No Persistence provider for EntityManager named em1" exception.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 06, 2006 12:52 pm 
Newbie

Joined: Sat Mar 04, 2006 12:17 pm
Posts: 4
for me it was missing libraries, but my persistence.xml is in the META-INF directory inside a (selfmade) jar-file under WEB-INF/lib and this is the right place as all stuff with hibernate resides in this jar.
So if your persistence.xml is in WEB-INF/classes/META-INF there must be also the classes under WEB-INF/classes I believe (unbundled).

Thread.currentThread().getContextClassLoader().getResource("META-INF/persistence.xml") works, sounds good.

my jars are:
ejb3-persistence
hibernate-annotations
hibernate-entitymanager
hibernate3
javassist.jar
jboss-archive-browsing
antlr-2.7.6rc1
asm-attrs
asm
cglib-2.1.3
commons-collections-2.1.1
commons-logging-1.0.4
dom4j-1.6.1
ehcache-1.1
jdbc2_0-stdext
jta
xml-apis
ufff, not all, but all related to hibernate I believe...


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 06, 2006 1:46 pm 
Newbie

Joined: Mon Dec 12, 2005 6:00 pm
Posts: 11
Turns out I was missing the entity manager jar and its dependents :)
Whoops!, I guess its been a long week.

Now the EntityManager stuff only fails with:
javax.persistence.PersistenceException: java.lang.IllegalArgumentException: could not instantiate ClassValidator

I assume that is completely unrelated, and should be easy to fix. Thanks for your help.

-jeff


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 06, 2006 1:47 pm 
Newbie

Joined: Tue Aug 09, 2005 3:03 pm
Posts: 14
is there anyway you can post your build file? I have all the jars but I think something in my build.xml is not working correctly.

thanks,

Khalid


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 06, 2006 2:18 pm 
Newbie

Joined: Mon Dec 12, 2005 6:00 pm
Posts: 11
I'm using maven 2. I wrote a simple shell script that primes the local maven repository with the versions of the jars that weren't available yet from ibiblio. Then made dependencies on them in my pom.xml so they get included in the war. Its not the most elegant solutions, but I didn't want to set up a maven repository.

pom.xml
Code:
<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/maven-v4_0_0.xsd">

    <modelVersion>4.0.0</modelVersion>

    <groupId>foo</groupId>

    <artifactId>foo</artifactId>

    <version>1.0-SNAPSHOT</version>

    <name>Foo Web Application</name>

    <packaging>war</packaging>

    <build>
        <defaultGoal>war:inplace</defaultGoal>

        <plugins>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.5</source>
                    <target>1.5</target>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.codehaus.cargo</groupId>
                <artifactId>cargo-maven2-plugin</artifactId>
                <configuration>
                    <container>
                        <containerId>tomcat5x</containerId>
                        <zipUrlInstaller>
                            <url>http://www.apache.org/dist/tomcat/tomcat-5/v5.5.16/bin/apache-tomcat-5.5.16.zip</url>
                        </zipUrlInstaller>
                    </container>
                    <configuration>
                        <home>${project.build.directory}/tomcat5x</home>
                        <deployables>
                            <deployable>
                                <location>${basedir}/src/main/webapp</location>
                            </deployable>
                        </deployables>
                    </configuration>
                </configuration>
                <executions>
                    <execution>
                        <id>start-container</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>start</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>stop-container</id>
                        <phase>post-integration-test</phase>
                        <goals>
                            <goal>stop</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

        </plugins>
    </build>

    <dependencies>

        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.9</version>
        </dependency>

        <dependency>
            <groupId>javax.persistence</groupId>
            <artifactId>ejb</artifactId>
            <version>3.0</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate</artifactId>
            <version>3.2.0.cr1</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-annotations</artifactId>
            <version>3.1beta9</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>3.1beta7</version>
        </dependency>

        <!-- Hibernate Dependencies -->
        <dependency>
            <groupId>antlr</groupId>
            <artifactId>antlr</artifactId>
            <version>2.7.6rc1</version>
        </dependency>

        <dependency>
            <groupId>asm</groupId>
            <artifactId>asm</artifactId>
            <version>2.2</version>
        </dependency>

        <dependency>
            <groupId>asm</groupId>
            <artifactId>asm-attrs</artifactId>
            <version>2.2</version>
        </dependency>

        <dependency>
            <groupId>c3p0</groupId>
            <artifactId>c3p0</artifactId>
            <version>0.9.0</version>
        </dependency>

        <dependency>
            <groupId>cglib</groupId>
            <artifactId>cglib</artifactId>
            <version>2.1_3</version>
        </dependency>

        <dependency>
            <groupId>commons-collections</groupId>
            <artifactId>commons-collections</artifactId>
            <version>2.1.1</version>
        </dependency>

        <dependency>
            <groupId>dom4j</groupId>
            <artifactId>dom4j</artifactId>
            <version>1.6.1</version>
        </dependency>

        <dependency>
            <groupId>ehcache</groupId>
            <artifactId>ehcache</artifactId>
            <version>1.1</version>
        </dependency>

        <dependency>
            <groupId>jta</groupId>
            <artifactId>jta</artifactId>
            <version>unknown</version>
        </dependency>

        <!-- End Hibernate Dependecies -->

        <!-- Hibernate Entity Manager Dependencies -->

        <dependency>
            <groupId>javassist</groupId>
            <artifactId>javassist</artifactId>
            <version>3.1</version>
        </dependency>

        <dependency>
            <groupId>org.jboss</groupId>
            <artifactId>jboss-archive-browsing</artifactId>
            <version>5.0.0alpha</version>
        </dependency>

        <!-- End Hibernate Entity Manager Dependencies -->

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.4</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jsp-api</artifactId>
            <version>2.0</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.1.2</version>
        </dependency>

        <dependency>
            <groupId>taglibs</groupId>
            <artifactId>standard</artifactId>
            <version>1.1.2</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring</artifactId>
            <version>1.2.6</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-mock</artifactId>
            <version>1.2.6</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.0.4</version>
        </dependency>

        <dependency>
            <groupId>commons-lang</groupId>
            <artifactId>commons-lang</artifactId>
            <version>2.1</version>
        </dependency>

        <dependency>
            <groupId>opensymphony</groupId>
            <artifactId>sitemesh</artifactId>
            <version>2.2.1</version>
        </dependency>

        <dependency>
            <groupId>jmock</groupId>
            <artifactId>jmock</artifactId>
            <version>1.0.1</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.postgres</groupId>
            <artifactId>jdbc</artifactId>
            <version>8.1</version>
        </dependency>
    </dependencies>

</project>



Shell script:
Code:
#!/bin/sh

mvn install:install-file -Dfile=lib/javax/persistence/ejb/3.0/ejb3-persistence.jar -DgroupId=javax.persistence -DartifactId=ejb -Dversion=3.0 -Dpackaging=jar -DgeneratePom=true
mvn install:install-file -Dfile=lib/org/hibernate/hibernate-annotations/3.1beta9/hibernate-annotations.jar -DgroupId=org.hibernate -DartifactId=hibernate-annotations -Dversion=3.1beta9 -Dpackaging=jar -DgeneratePom=true
mvn install:install-file -Dfile=lib/org/hibernate/hibernate-entitymanager/3.1beta7/hibernate-entitymanager.jar -DgroupId=org.hibernate -DartifactId=hibernate-entitymanager -Dversion=3.1beta7 -Dpackaging=jar -DgeneratePom=true
mvn install:install-file -Dfile=lib/org/hibernate/hibernate/3.2.0.cr1/hibernate3.jar -DgroupId=org.hibernate -DartifactId=hibernate -Dversion=3.2.0.cr1 -Dpackaging=jar -DgeneratePom=true
mvn install:install-file -Dfile=lib/org/postgresql/jdbc/8.1/postgresql-jdbc-8.1.jar -DgroupId=org.postgres -DartifactId=jdbc -Dversion=8.1 -Dpackaging=jar -DgeneratePom=true
mvn install:install-file -Dfile=lib/jta/jta/unknown/jta.jar -DgroupId=jta -DartifactId=jta -Dversion=unknown -Dpackaging=jar -DgeneratePom=true
mvn install:install-file -Dfile=lib/javassist/javassist/3.1/javassist.jar -DgroupId=javassist -DartifactId=javassist -Dversion=3.1 -Dpackaging=jar -DgeneratePom=true
mvn install:install-file -Dfile=lib/org/jboss/jboss-archive-browsing/5.0.0alpha/jboss-archive-browsing.jar -DgroupId=org.jboss -DartifactId=jboss-archive-browsing -Dversion=5.0.0alpha -Dpackaging=jar -DgeneratePom=true
Code:


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 10 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.