I encouter a problem when running maven test + jpa + mysql. The report result 
always shows that `No Persistence provider for EntityManager named jpa' (where 
jpa is the persistent-unit name specified in the persistence.xml under 
src/main/resources/META-INF). It looks like the test (e.g. mvn test) can not 
find the persistence.xml file; however, a tutorial I found out on the internet 
- 
http://www.stripesbook.com/blog/index.php?/archives/34-Java-Persistence-Maven-2,-JPA,-and-Hibernate-Quickstart.html,
 its source code structure is similar to mine and its test can be executed 
without a problem. 

Where should I specify the persistence.xml path so that the mvn test will pick 
up the persistence unit (I try specify persistence.xml in 
test/resources/META-INF folder it doesn't work as well)? Or where should I 
check that might cause such problem?

I appreciate any help.

env: debian kernel 2.6.30-1/ java 1.6.0_10/ maven 2.0.9

exception:

Caused by: javax.persistence.PersistenceException: No Persistence provider for 
EntityManager named jpa
        at 
javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:89)
        at 
javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:60)
        at 
exmample.domain.PersistenceProvider.<clinit>(PersistenceProvider.java:35)
        ... 63 more


PersistenceProvider.java

public class PersistenceProvider{

        public static final String PERSISTENCE_UNIT_NAME = "jpa";
        private static EntityManagerFactory factory;

        static {
                try {
                        factory = 
Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
                }catch(Throwable t) {
                        throw new ExceptionInInitializerError(t);
                }
        }
 
        public static EntityManagerFactory createPersistenceFactory() {
                return factory;
        }
 
        public static void close() {
                if(null == factory)
                        throw new NullPointerException("No EntityManagerFactory 
available!");
                factory.close();
        }       
}

persistence.xml

<persistence xmlns="http://java.sun.com/xml/ns/persistence";
 xmlns:xsi="http://www.23.org/2001/XMLSchema-instance";
 xsi:schemaLocation="http://java.sun.com/ns/persistence
 http://java.sun.com/ns/persistence/persistence_1_0.xsd";
 version="1.0">
    <persistence-unit name="jpa">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        
        <properties>
            <property name="hibernate.archive.autodetection"
                      value="class, hbm"/>
 
            <property name="hibernate.show_sql" value="true"/>
            <property name="hibernate.format_sql" value="true"/>
        
            <property name="hibernate.dialect" 
                      value="org.hibernate.dialect.MySQLDialect"/> 
            <property name="hibernate.connection.driver_class" 
                      value="com.mysql.jdbc.Driver"/> 
            <property name="hibernate.connection.url" 
                      value="jdbc:mysql://localhost/demo"/> 
        
            <property name="hibernate.connection.username" value="root"/> 
            <property name="hibernate.connection.password" value="*****"/> 
            <!--property name="hibernate.hbm2ddl.auto" value="create"/-->
        </properties>
    </persistence-unit>
</persistence> 

pom.xml

        <dependencies>

        <!-- bsh -->
        <dependency>
                <groupId>org.beanshell</groupId>
                <artifactId>bsh</artifactId>
                <version>2.0b4</version>
        </dependency> 

        <!-- aspectj -->
        <dependency>
                <groupId>aspectj</groupId>
                <artifactId>aspectjrt</artifactId>
                <version>1.5.4</version>
        </dependency>

        <!-- tapestry -->
        <dependency>
                <groupId>org.apache.tapestry</groupId>
                <artifactId>tapestry-core</artifactId>
                <version>${tapestry-release-version}</version>
        </dependency>
        <dependency>
                <groupId>org.apache.tapestry</groupId>
                <artifactId>tapestry-ioc</artifactId>
                <version>${tapestry-release-version}</version>
        </dependency>
        <dependency>
                <groupId>org.apache.tapestry</groupId>
                <artifactId>tapestry5-annotations</artifactId>
                <version>${tapestry-release-version}</version>
        </dependency>

        <!-- hibernate -->
        <dependency>
                <groupId>org.hibernate</groupId>
                <artifactId>hibernate</artifactId>
                <version>3.2.2.ga</version>
                <exclusions>
                        <exclusion>
                                <artifactId>jta</artifactId>
                                <groupId>javax.transaction</groupId>
                        </exclusion>
                </exclusions>
        </dependency>
        <dependency>
                <groupId>c3p0</groupId>
                <artifactId>c3p0</artifactId>
                <version>0.9.0</version>
        </dependency>
        <dependency>
                <groupId>org.apache.tapestry</groupId>
                <artifactId>tapestry-hibernate</artifactId>
                <version>5.1.0.5</version>
        </dependency> 
        <dependency>
                <groupId>org.apache.tapestry</groupId>
                <artifactId>tapestry-hibernate-core</artifactId>
                <version>5.1.0.5</version>
        </dependency>
        <dependency>
                <groupId>org.apache.geronimo.specs</groupId>
                <artifactId>geronimo-jta_1.0.1B_spec</artifactId>
                <version>1.1</version>
        </dependency>
        <dependency>
                <groupId>org.hibernate</groupId>
                <artifactId>hibernate-annotations</artifactId>
                <version>3.2.1.ga</version>
        </dependency>

        <!-- mysql -->
        <dependency>
                <groupId>mysql</groupId>
                <artifactId>mysql-connector-java</artifactId>
                <version>3.1.12</version>
        </dependency>

        <!-- junit -->
        <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>4.6</version>
                <scope>test</scope>
        </dependency> 

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

        <build>
                <finalName>jecommerce</finalName>
                <plugins>
                        <plugin>
                                <groupId>org.apache.maven.plugins</groupId>
                                <artifactId>maven-compiler-plugin</artifactId>
                                <configuration>
                                        <source>1.5</source>
                                        <target>1.5</target>
                                        <optimize>true</optimize>
                                </configuration>
                        </plugin>
                        <plugin>
                                <groupId>org.apache.maven.plugins</groupId>
                                <artifactId>maven-war-plugin</artifactId>
                                <configuration>
                                        <webResources>
                                                <resource>
                                                        
<directory>src/main/resources/META-INF</directory>
                                                         override the 
destination directory for this resource 
                                                        
<targetPath>META-INF</targetPath>
                                                        <includes>
                                                                
<include>persistence.xml</include>
                                                        </includes>
                                                </resource>
                                        </webResources>
                                </configuration>
                        </plugin>
                        <plugin>
                                <groupId>org.codehaus.mojo</groupId>
                                <artifactId>aspectj-maven-plugin</artifactId>
                                <configuration>
                                        <source>1.5</source>
                                        <complianceLevel>1.5</complianceLevel>
                                </configuration>
                                <executions>
                                        <execution>
                                                <goals>
                                                        <goal>compile</goal>
                                                        
<goal>test-compile</goal>
                                                </goals>
                                        </execution>
                                </executions>
                        </plugin>
                </plugins>
        </build>






---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to