How to use JPA EntityManager in java SE applications
<p>I'm working on a java SE application and I want to use JPA EntityManager for managing database operations. From my searches, I found that there is need to make a <code>persistence.xml</code> file. But I don't know where should I put it. My search results say it should be place in the <code>webRoot\META-INF</code>, but my project it's not a J2EE project, so it has not webRoot or META-INF directories. Here is my code for getting entity manager:</p>

<pre><code> private static EntityManagerFactory factory = Persistence.createEntityManagerFactory("unitName");
 protected EntityManager entityManager =  entityManager = factory.createEntityManager();
</code></pre>

<p>But this always causes <code>javax.persistence.PersistenceException</code> exception and return me this message:</p>

<pre><code>No Persistence provider for EntityManager named unitName
</code></pre>

<p>How can I solve this problem? </p>

<p>Thank you for your attention.</p>