4

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

1 Answer 1

1

According to your WEB-INF/lib content, there is no Hibernates's libraries.

So please download its libraries and add them to your WEB-INF/lib folder.

Here is a list of necessary libraries (note, that javax.persistence.jar you need to remove to avoid possible JARs conflict):

  • antlr-2.7.7.jar
  • dom4j-1.6.1.jar
  • hibernate-commons-annotations-4.0.1.Final.jar
  • hibernate-core-4.1.8.Final.jar
  • hibernate-entitymanager-4.1.8.Final.jar
  • hibernate-jpa-2.0-api-1.0.1.Final.jar
  • javassist-3.15.0-GA.jar
  • jboss-logging-3.1.0.GA.jar
  • jboss-transaction-api_1.1_spec-1.0.0.Final.jar
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. i thought IntelliJ added them automatically. Works fine now :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.