i'm trying to learn using persistence and already managed to run the project successfully on glassfish on my local machine. Now the next step for me was to run it on my server on Tomcat, but this doesn't work.
I always get the error "No Persistence provider for EntityManager named MyPersistence"
This is what the structure of the War looks like
.
|____index.jsp
|____WEB-INF
| |____classes
| | |____Mainpackage
| | | |____Ente.class
| | |____META-INF
| | | |____persistence.xml
| |____lib
| | |____javax.persistence.jar
| | |____mysql-connector-java-5.1.24-bin.jar
| |____web.xml
the content of my jsp is
EntityManagerFactory fac = Persistence.createEntityManagerFactory("MyPersistence");
EntityManager mgr = fac.createEntityManager();
mgr.getTransaction().begin();
Ente e = new Ente();
e.setName("Quietscheente");
mgr.persist(e);
mgr.getTransaction().commit();
mgr.close();
fac.close();
and my persistence.xml looks like
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0">
<persistence-unit name="MyPersistence">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.connection.url" value="jdbc:mysql://h2134265.stratoserver.net/persistencetest"/>
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
<property name="hibernate.connection.username" value="persistence"/>
<property name="hibernate.connection.password" value="XXXXXXXXX"/>
<property name="hibernate.archive.autodetection" value="class"/>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.format_sql" value="true"/>
<property name="hbm2ddl.auto" value="update"/>
</properties>
<class>Mainpackage.Ente</class>
</persistence-unit>
</persistence>
I did try to move the persistence.xml to another location, but according to several sources on the internet the location should be correct