Note that there are some explanatory texts on larger screens.

plurals
  1. POJPA persist() method is not doing its job
    text
    copied!<p>I am working on a JPA, jsf2.0 Hibernate project. It is a management of the user's actions through a primefaces calendar that you can see <a href="http://www.primefaces.org/showcase/ui/schedule.jsf" rel="nofollow">here</a>.</p> <p>I managed to get user's actions and display them in the calendar, but when I want to add a new action it seems to work: I have no error message but in reality the action is not added in database. It seems like the persist method is not doing its job, it is not returning any error message so I don't know what to do to see why.</p> <p>I put you here the 2 functions for these 2 actions (display and add):</p> <p>Method to add an action (it does not work)</p> <pre><code>public void creerAction(Action action){ Date date = action.getDateAction(); action.setDateAction(date); EntityManagerFactory emf = null; try{ emf = Persistence.createEntityManagerFactory("GA2010-ejbPU-dev"); em = emf.createEntityManager(); em.persist(action); FacesMessage message = new FacesMessage("Action " + action.getTexteAction()+ " ajouté avec succès"); FacesContext.getCurrentInstance().addMessage(null, message); }catch(PersistenceException e){ System.out.println(e.getMessage()); } } </code></pre> <p>and the method to get all actions of an user (it works)</p> <pre><code>public List&lt;Action&gt; getAllAction(){ HttpSession sess = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(true); String codeUser = (String) sess.getAttribute("codeUser"); EntityManagerFactory emf = null; try{ emf = Persistence.createEntityManagerFactory("GA2010-ejbPU-dev"); em = emf.createEntityManager(); Query requete = em.createQuery(SELECT_ALL_ACTION); requete.setParameter("codeUtilisateur", codeUser); this.allAction= requete.getResultList(); }catch(Exception e){ this.message = new FacesMessage(e.getMessage()) ; FacesContext.getCurrentInstance().addMessage( null, message ); } return allAction; } </code></pre> <p>And here is the declaration of my unit persistence</p> <pre><code>&lt;persistence-unit name="GA2010-ejbPU-dev" transaction-type="JTA"&gt; &lt;provider&gt;org.eclipse.persistence.jpa.PersistenceProvider&lt;/provider&gt; &lt;jta-data-source&gt;dev&lt;/jta-data-source&gt; &lt;class&gt;entities.Utilisateur&lt;/class&gt; &lt;class&gt;entities.Action&lt;/class&gt; &lt;properties&gt; &lt;property name="eclipselink.target-server" value="SunAS9"/&gt; &lt;property name="eclipselink.logging.level" value="FINE"/&gt; &lt;property name="eclipselink.ddl-generation" value="drop-and-create-tables"/&gt; &lt;property name="eclipselink.ddl-generation.output-mode" value="sql-script"/&gt; &lt;property name="eclipselink.application-location" value="C:/tmp"/&gt; &lt;/properties&gt; </code></pre> <p></p> <p>How can I see why persist does not persist and why I am not having an error message?</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