title: EntityManager persist() method does not insert record to database => SEVERE: javax.persistence.TransactionRequiredException
body: <p>I have problem with using EntityManager persist() method.
  I am using JSF2.0, glassfish 3, JPA and hibernate, i am not using spring.</p>
  
  <p>I try to add events in an events table with the method persist, but EntityManager persist() method does not insert record to database and i have this error message =></p>
  
  <p>SEVERE: javax.persistence.TransactionRequiredException
      at com.sun.enterprise.container.common.impl.EntityManagerWrapper.doTxRequiredCheck(EntityManagerWrapper.java:163)
      at com.sun.enterprise.container.common.impl.EntityManagerWrapper.flush(EntityManagerWrapper.java:411)
      at dao.EvenementDao.addEvenement(EvenementDao.java:128).</p>
  
  <pre><code>@ManagedBean
  @Stateless
  public class EvenementDao implements Serializable{
  
  /**
   * 
   */
  private static final long serialVersionUID = -3343483942392617877L;
  /**
   * 
   */
  
  
  private List&lt;TEvenement&gt;  listeEvenement;
  private List&lt;SelectItem&gt; listeSelectItemEvnt;
  private TEvenement tevenement ;
  
  
  
  
  public EvenementDao() {
  
  }
  
  
  @PersistenceUnit(unitName="GA2010-ejbPU-dev")
  private EntityManagerFactory emf;
  
  
  
  @PostConstruct
  private void init() {
  
      tevenement = new TEvenement();
  
  }
  
  
  
  public List&lt;TEvenement&gt; getListeEvenement() {
  EntityManager em = emf.createEntityManager();
      TypedQuery&lt;TEvenement&gt; requete = m.createNamedQuery("TEvenement.findPrivateOther", 
      TEvenement.class);
      listeEvenement = requete.getResultList();
  
      return listeEvenement;
  }
  
  public TEvenement getEvenement() {
      return tevenement;
  }
  
  
  
  public void setEvenement(TEvenement evenement) {
      this.tevenement = evenement;
  }
  
  
  
  public void addEvenement(){
      EntityManager em = emf.createEntityManager();
  HttpSession session = (HttpSession) FacesContext.getCurrentInstance().
                            getExternalContext().getSession(false);
      Integer codeUser = (Integer) session.getAttribute("codeUser");
      tevenement.setUtilCreation(codeUser);
  
      System.out.println("je rentre dans addevenemnt");
      try{
  
  
  
  
          System.out.println("i persist "+ em);
  
              em.persist(tevenement);
              em.flush();
          System.out.println(tevenement.getDetailsEvenement());
  
          FacesMessage message = new FacesMessage("Evenement ajouté avec succès.");
          FacesContext.getCurrentInstance().addMessage(null, message);
  
  
      }catch(Exception e){
          e.printStackTrace();
      }
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>So, this is not working, but the progam enter in the fonction addEvenement , FacesMessage message = new FacesMessage("Evenement ajouté avec succès."); returns me the message as if it was working.
  i thouht it was due to my entityMAnager but in fact an ohter function works fine with the same Entity manager so i dont understand.</p>
  
  <pre><code>**public List&lt;TEvenement&gt; getListeEvenement()** {
      EntityManager em = emf.createEntityManager();
      TypedQuery&lt;TEvenement&gt; requete =     em.createNamedQuery("TEvenement.findPrivateOther", TEvenement.class);
      listeEvenement = requete.getResultList();
  
      return listeEvenement;
  }
  </code></pre>
  
  <p>this one works fine, the only difference is  that in this case the query is a select and in the other case it's a persist so a query that impact the database. </p>
  
  <p>the code of the entity : </p>
  
  <p>@Entity
  @Table(name="t_evenements")
  @NamedQueries({@NamedQuery(name="TEvenement.findAll", query="SELECT evnt FROM TEvenement evnt"), 
          @NamedQuery(name="TEvenement.findPrivateOther", query="SELECT evnt FROM TEvenement evnt WHERE evnt.typeEvenement = 6 OR evnt.typeEvenement = 7")})
  public class TEvenement implements Serializable {</p>
  
  <pre><code>private static final long serialVersionUID = -1908959833491896991L;
  
  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  @Column(name="REF_EVENEMENT", unique=true, nullable=false)
  private Integer refEvenement;
  
  @Temporal(TemporalType.DATE)
  @Column(name="DATE_DEBUT_EVENEMENT")
  private Date dateDebutEvenement;
  
  @Temporal(TemporalType.DATE)
  @Column(name="DATE_FIN_EVENEMENT")
  private Date dateFinEvenement;
  
  @Column(name="DETAILS_EVENEMENT")
  private String detailsEvenement;
  
  @Column(name="IS_EVERYDAY")
  private byte isEveryday;
  
  @Column(name="RAPPEL_EVENEMENT")
  private int rappelEvenement;
  
  public Integer getUtilEvenement() {
      return utilEvenement;
  }
  
  public void setUtilEvenement(Integer utilEvenement) {
      this.utilEvenement = utilEvenement;
  }
  
  @Column(name="TITRE_EVENEMENT")
  private String titreEvenement;
  
  @Column(name="TYPE_EVENEMENT")
  private String typeEvenement;
  
  @Column(name="UTIL_COPIE_EVENEMENT")
  private Integer utilCopieEvenement;
  
  @Column(name="UTIL_EVENEMENT")
  private Integer utilEvenement;
  
  @Column(name="HEURE_EVENEMENT")
  private String heureEvenement;
  
  @Column(name="UTIL_CREATION")
  private Integer  utilCreation;
  
  
  public String getHeureEvenement() {
      return heureEvenement;
  }
  
  public void setHeureEvenement(String heureEvenement) {
      this.heureEvenement = heureEvenement;
  }
  
  public TEvenement() {
  }
  
  public Integer getRefEvenement() {
      return this.refEvenement;
  }
  
  public void setRefEvenement(int refEvenement) {
      this.refEvenement = refEvenement;
  }
  
  public Date getDateDebutEvenement() {
      return this.dateDebutEvenement;
  }
  
  public Integer getUtilCreation() {
      return utilCreation;
  }
  
  public void setUtilCreation(Integer utilCreation) {
      this.utilCreation = utilCreation;
  }
  
  public void setUtilCopieEvenement(Integer utilCopieEvenement) {
      this.utilCopieEvenement = utilCopieEvenement;
  }
  
  public void setDateDebutEvenement(Date dateDebutEvenement) {
      this.dateDebutEvenement = dateDebutEvenement;
  }
  
  public Date getDateFinEvenement() {
      return this.dateFinEvenement;
  }
  
  public void setDateFinEvenement(Date dateFinEvenement) {
      this.dateFinEvenement = dateFinEvenement;
  }
  
  public String getDetailsEvenement() {
      return this.detailsEvenement;
  }
  
  public void setDetailsEvenement(String detailsEvenement) {
      this.detailsEvenement = detailsEvenement;
  }
  
  public byte getIsEveryday() {
      return this.isEveryday;
  }
  
  public void setIsEveryday(byte isEveryday) {
      this.isEveryday = isEveryday;
  }
  
  public int getRappelEvenement() {
      return this.rappelEvenement;
  }
  
  public void setRappelEvenement(int rappelEvenement) {
      this.rappelEvenement = rappelEvenement;
  }
  
  public String getTitreEvenement() {
      return this.titreEvenement;
  }
  
  public void setTitreEvenement(String titreEvenement) {
      this.titreEvenement = titreEvenement;
  }
  
  public String getTypeEvenement() {
      return this.typeEvenement;
  }
  
  public void setTypeEvenement(String typeEvenement) {
      this.typeEvenement = typeEvenement;
  }
  
  public Integer getUtilCopieEvenement() {
      return this.utilCopieEvenement;
  }
  
  public void setUtilCopieEvenement(int utilCopieEvenement) {
      this.utilCopieEvenement = utilCopieEvenement;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Do anyone have a idea what am i missing?</p>