I’m building a JAX-RS web service (Jersey) and now I’m trying to start using JPA. I have selected eclipselink to manage this persistence.
To start off, I’m writing some junit test cases until I figure out how everything will come together.
In my persistence.xml (WEB-INF/persistence.xml) I have:
<?xml version="1.0" encoding="UTF-8" ?>
<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_2_0.xsd"
version="2.0" xmlns="http://java.sun.com/xml/ns/persistence">
<persistence-unit name="ws-persist" transaction-type="RESOURCE_LOCAL">
<class>beans.Change</class>
<properties>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3333/tomcat" />
<property name="javax.persistence.jdbc.user" value="tomcat" />
<property name="javax.persistence.jdbc.password" value="...." />
<property name="eclipselink.ddl-generation" value="create-tables" />
<property name="eclipselink.ddl-generation.output-mode" value="database" />
</properties>
</persistence-unit>
In my test class I have.
public class PersistenceTests {
private EntityManager em = null;
@Before
public void setUp() throws Exception {
Properties propertiesMap = new Properties();
propertiesMap.put(PersistenceUnitProperties.DDL_GENERATION, PersistenceUnitProperties.DROP_AND_CREATE);
EntityManagerFactory factory = Persistence.createEntityManagerFactory("ws-persist", propertiesMap);
em = factory.createEntityManager();
}
@After
public void tearDown() throws Exception {
}
@Test
public void testSetUp(){
Assert.assertNotNull("Entity manager was null", em);
Assert.assertTrue("Entity manager wasn't connected", em.isOpen());
}
}
I have eclipselink.jar, and two javax.persistence_*.jars under my WEB-INF/lib folder.
I’m getting the exception metioned in the title, can someone please help me figure out how to fix this?
Thanks.
I would try to add the persistence provider in the persistence.xml
(edit) or moving persistence.xml to
META-INFfolder. For a web-app this has to be inWEB-INF/classes