Note that there are some explanatory texts on larger screens.

plurals
  1. POJPA Unknown Source
    text
    copied!<p>I'm creating my first JPA application using NetBeans. I'm unable to make the persistence work. The connection to database works well, when I run the application the database tables got created. But when I try to create EntityManagerFactory:</p> <pre><code>EntityManagerFactory emf = Persistence.createEntityManagerFactory("PISProjektPU"); </code></pre> <p>I get: </p> <pre><code>INFO: javax.persistence.PersistenceException: [PersistenceUnit: PISProjektPU] Unable to build EntityManagerFactory at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:677) at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:126) at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:78) at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54) at cz.vutbr.fit.pis.spravaTechniky.service.TestManager.&lt;init&gt;(TestManager.java:28) at cz.vutbr.fit.pis.spravaTechniky.service.__EJB31_Generated__TestManager__Intf____Bean__.&lt;init&gt;(Unknown Source) ... </code></pre> <p>My persistence.xml file looks like this (generated by NetBeans, I didn't change anything):</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"&gt; &lt;persistence-unit name="PISProjektPU" transaction-type="JTA"&gt; &lt;provider&gt;org.hibernate.ejb.HibernatePersistence&lt;/provider&gt; &lt;jta-data-source&gt;jdbc/myslq_spravaTechniky&lt;/jta-data-source&gt; &lt;class&gt;cz.vutbr.fit.pis.spravaTechniky.data.TestEntity&lt;/class&gt; &lt;exclude-unlisted-classes&gt;true&lt;/exclude-unlisted-classes&gt; &lt;properties&gt; &lt;/properties&gt; &lt;/persistence-unit&gt; &lt;/persistence&gt; </code></pre> <p>and it's located here:</p> <pre><code>src/conf/persistence.xml build/web/WEB-INF/classes/META-INF/persistence.xml </code></pre> <p>I searched the forum and found some tips how to remove this error, but I was unable to make it work. I tried to add these two lines to Manifest.mf:</p> <pre><code>Meta-Persistence: META-INF/persistence.xml JPA-PersistenceUnits: PISProjektPU </code></pre> <p>I tried to move the persistence.xml file to all possible locations. I also added all libraries that seemed like they might be useful, when I go to Properties/Libraries, I see:</p> <pre><code>Java EE 6 API Library Hibernate Java-EE-GlassFish-v3 EclipseLink(JPA 2.0) EclipseLink-GlassFish-v3 Hibernate JPA JSF 2.0 Java EE Web 6 API Library Persistence </code></pre> <p>I'm sure I'm doing some stupid simple mistake, but after a day trying to make this work I am unable to see where is the problem. To be honest right now I'm just totally confused about where to put which file or how to configure everything, so I'm randomly trying different things. I will be thankful for any advice!</p> <h2>Edit:</h2> <p>Thanks for the suggestion. My test classes actually look like this:</p> <p>Class TestManager:</p> <pre><code>@Stateless public class TestManager { @PersistenceContext private EntityManager em; public void save(TestEntity t) { em.merge(t); } public void remove(TestEntity t) { em.remove(em.merge(t)); } public void create(TestEntity t) { em.persist(t); } @SuppressWarnings("unchecked") public List&lt;TestEntity&gt; findAll() { return em.createQuery("SELECT t FROM TestEntity t").getResultList(); } } </code></pre> <p>Class TestBean:</p> <pre><code>@Named(value="testBean") @Dependent public class TestBean { @EJB private TestManager testManager; /** Creates a new instance of TestBean */ public TestBean() { } public List&lt;TestEntity&gt; getEntities() { return this.testManager.findAll(); } } </code></pre> <p>I'm calling the TestBean.getEntities method:</p> <pre><code>... &lt;h:dataTable value="#{testBean.entities}" var="entity"&gt; ... </code></pre> <p>This causes the following exception:</p> <pre><code>javax.ejb.EJBException at com.sun.ejb.containers.BaseContainer.processSystemException(BaseContainer.java:5119) at com.sun.ejb.containers.BaseContainer.completeNewTx(BaseContainer.java:5017) at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:4805) at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:2004) at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:1955) at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:198) at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:84) at $Proxy141.findAll(Unknown Source) at cz.vutbr.fit.pis.spravaTechniky.service.__EJB31_Generated__TestManager__Intf____Bean__.findAll(Unknown Source) at cz.vutbr.fit.pis.spravaTechniky.back.TestBean.getEntities(TestBean.java:27) ... </code></pre> <p>I tried to replace the @PersistenceContext with @EJB, but got <code>javax.ejb.EJBException: javax.ejb.CreateException: Could not create stateless EJB</code>.</p>
 

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