Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to use persistence.xml and hibernate.cfg.xml in JUnit tests via eclipse?
    primarykey
    data
    text
    <p>I have been searching for an answer during quite a long time before coming here and ask this question. My problem is very simple : I cannot run any JUnit test when using the JPA Entity Manager API. It seems that my test is not reading the <code>persistence.xml</code> file.</p> <p>When I call <code>new Configuration().configure().buildSessionFactory()</code>, it works like a charm but an exception is thrown when calling <code>Persistence.createEntityManagerFactory("myapp")</code> is:</p> <blockquote> <p>javax.persistence.PersistenceException: No Persistence provider for EntityManager named myapp at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:69) at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47) at com.myapp.Test01.setUpBeforeClass(Test01.java:22)</p> </blockquote> <p>My JavaSE project has the following structure :</p> <pre><code>myapp ++src/main/java ++com.myapp.model ++// My entity classes are here ++src/test/java ++com.myapp ++Test01.java ++src/main/resources ++hibernate.cfg.xml ++META-INF ++persistence.xml </code></pre> <p>and <code>persistence.xml</code> looks like:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0"&gt; &lt;persistence-unit name="myapp" transaction-type="RESOURCE_LOCAL"&gt; &lt;provider&gt;org.hibernate.ejb.HibernatePersistence&lt;/provider&gt; &lt;properties&gt; &lt;property name="hibernate.ejb.cfgfile" value="hibernate.cfg.xml"&gt;&lt;/property&gt; &lt;/properties&gt; &lt;/persistence-unit&gt; &lt;/persistence&gt; </code></pre> <p>Do you have any idea how to solve this issue ?</p> <p>Thank you very much for your help.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload