I am trying to learn how to use perseverance and have already managed to successfully launch a project on a glass fish on my local machine. Now the next step for me was to run it on my server on Tomcat, but that would not work.
I always get the error "There is no entity provider for EntityManager named MyPersistence"
This is what the structure of 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 contents of my jsp
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 tried moving persistence.xml to another place, but according to several sources on the internet, the location should be correct.
source share