Hi,
When i'm running my junit testcase from maven2 getting the error "No Persistence provider for EntityManager"
.
I have done lots of googling still struggling,
Looks testcases not able to find persistence.xml but why?
Is any body a have faced this issue?
Thank you
[b]( Inside target\surefire-reports\mytest.txt)[/b]
javax.persistence.PersistenceException: No Persistence provider for EntityManager named TestPU: Provider named oracle.toplink.essentials.PersistenceProvider threw unexpected exception at create EntityManagerFactory:
java.lang.AssertionError
java.lang.AssertionError
at oracle.toplink.essentials.ejb.cmp3.persistence.PersistenceUnitProcessor.computePURootURL(PersistenceUnitProcessor.java:263)
at oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider.createEntityManagerFactory(EntityManagerFactoryProvider.java:148)
==================================================================================================================
[b]src/test/resources/META-INF/persistence.xml[/b]
==============
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" 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">
<persistence-unit name="TestPU" transaction-type="RESOURCE_LOCAL">
<provider>oracle.toplink.essentials.PersistenceProvider</provider>
<class>ABCEntity</class>
<properties>
<property name="toplink.jdbc.url" value="jdbc:mysql://localhost:3306/testdb"/>
<property name="toplink.jdbc.user" value="test1"/>
<property name="toplink.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="toplink.jdbc.password" value="test123"/>
<property name="toplink.ddl-generation" value="none"/>
<property name="toplink.logging.level" value="fine"/>
<property name="toplink.jdbc.native-sql" value="true"/>
<property name="toplink.target-database" value="MySQL4"/>
</properties>
</persistence-unit>
</persistence>
[b]pom.xml[/b]
.............
..........
...
<resources>
<resource>
<filtering>false</filtering>
<directory>${basedir}/src/main/resources</directory>
<includes>
<include>META-INF/persistence.xml</include>
</includes>
</resource>
</resources>
<testResources>
<testResource>
<directory>${basedir}/src/test/resources</directory>
<includes>
<include>META-INF/persistence.xml</include>
</includes>
</testResource>
</testResources>
....
...
...
<dependency>
<groupId>com.oracle.toplink</groupId>
<artifactId>toplink</artifactId>
<version>10.1.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.5</version>
<scope>test</scope>
</dependency>
...............
............
TestCase
@Test
public void testBalance() {
javax.persistence.EntityManagerFactory emf =
javax.persistence.Persistence.createEntityManagerFactory("TestPU");
assertNotNull("The entity manager factory is null", emf);
...
....
...
..
}
[Message sent by forum member 'happy007' (happy007)]
http://forums.java.net/jive/thread.jspa?messageID=299556