title: JPA does not insert entity to database
body: <p>I work with hibernate-jpa-2.1-api</p>
  
  <p>I have an EJB class for busines logic</p>
  
  <p>I have made an @RequestScopded EntityManager that is injected in the EJB and called in the save method, there is no error but even no entry in the database. The funny thing is that the hibernate sequence number is increased in the DB correctly but the insert of the entity is not called, I dont even see the insert statement for the entity in the logs.</p>
  
  <p>if I call </p>
  
  <blockquote>
    <p>em.flush()</p>
  </blockquote>
  
  <p>after </p>
  
  <blockquote>
    <p>em.persist()</p>
  </blockquote>
  
  <p>I get an error that tells there is no transaction in progress.</p>
  
  <p>I have othere save metods for other entities organised the same way and are working correctly. I have also tryed to inject the EntityManager in the EJB as @PersistenceContect and in that case it is working, but I wonder why in this specific case the requesed scoped EM is not working and in other it does.</p>
  
  <p>Here is my code:</p>
  
  <p>1.) the Entity</p>
  
  <pre><code>@Entity
  @Table(name = "CONSULTATION")
  public class Consultation implements java.io.Serializable {
  
  private static final long serialVersionUID = 2989793280017282405L;
  private long idConsulation;
  private DomainExpert domainExpert;
  private Date date;
  private Long hours;
  private String description;
  private PayedResource payedResource;
  private Integer version;
  
  public Consultation() {
  }
  
  public Consultation(long idConsulation, DomainExpert domainExpert) {
      this.idConsulation = idConsulation;
      this.domainExpert = domainExpert;
  }
  
  public Consultation(long idConsulation, DomainExpert domainExpert, Date date, Long hours) {
      this.idConsulation = idConsulation;
      this.domainExpert = domainExpert;
      this.date = date;
      this.hours = hours;
  }
  
  @Id
  @TableGenerator(name = "ID_CONSULATION", table = "hibernate_sequence", pkColumnName = "SEQUENCE_NAME", valueColumnName = "NEXT_VAL", pkColumnValue = "SEQ_ID_CONSULATION", allocationSize = 1)
  @GeneratedValue(strategy = GenerationType.TABLE, generator = "ID_CONSULATION")
  @Column(name = "ID_CONSULATION", unique = true, nullable = false)
  public long getIdConsulation() {
      return this.idConsulation;
  }
  
  public void setIdConsulation(long idConsulation) {
      this.idConsulation = idConsulation;
  }
  
  @ManyToOne(fetch = FetchType.LAZY)
  @JoinColumn(name = "ID_DOMAIN_EXPERT", nullable = false)
  public DomainExpert getDomainExpert() {
      return this.domainExpert;
  }
  
  public void setDomainExpert(DomainExpert domainExpert) {
      this.domainExpert = domainExpert;
  }
  
  @Temporal(TemporalType.TIMESTAMP)
  @Column(name = "DATE", length = 19, nullable = false)
  public Date getDate() {
      return this.date;
  }
  
  public void setDate(Date date) {
      this.date = date;
  }
  
  @Column(name = "HOURS", length = 20, nullable = false)
  public Long getHours() {
      return this.hours;
  }
  
  public void setHours(Long hours) {
      this.hours = hours;
  }
  
  @Column(name = "DESCRIPTION", length = 500)
  public String getDescription() {
      return description;
  }
  
  public void setDescription(String description) {
      this.description = description;
  }
  
  @Version
  @Column(name = "VERSION", nullable = false)
  public Integer getVersion() {
      return this.version;
  }
  
  public void setVersion(Integer version) {
      this.version = version;
  }
  
  @ManyToOne(fetch = FetchType.LAZY)
  @JoinColumn(name = "ID_PAYED_RESOURCE", nullable = false)
  public PayedResource getPayedResource() {
      return this.payedResource;
  }
  
  public void setPayedResource(PayedResource payedResource) {
      this.payedResource = payedResource;
  }
  
  }
  </code></pre>
  
  <p>2.) the EJB</p>
  
  <pre><code>@Stateless
  public class DomainExpertHandler {
  
      @Inject
      private EntityManager em;
  
      public void saveConsultation(Consultation consultation) {
         if (consultation.getIdConsulation() &gt; 0) {
           em.merge(consultation);
         } else {
           em.persist(consultation);
         }
      }
  }
  </code></pre>
  
  <p>3.) The bean that generates the @requestscoped EM</p>
  
  <pre><code>public class Resources {
  
      @PersistenceUnit
      EntityManagerFactory emf;
  
      @Produces
      @RequestScoped
      public EntityManager createEntityManager() {
          return emf.createEntityManager();
      }
  
      protected void closeEntityManager(@Disposes EntityManager entityManager) {
  
          if (entityManager.isOpen()) {
              entityManager.close();
          }
      }
  
  
  }
  </code></pre>
  
  <p>4.) my persistence.xml</p>
  
  <pre><code>&lt;persistence version="2.1"
     xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="
          http://xmlns.jcp.org/xml/ns/persistence
          http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"&gt;
  
     &lt;persistence-unit  name="cloudflow" transaction-type="JTA"&gt;
          &lt;provider&gt;org.hibernate.jpa.HibernatePersistenceProvider&lt;/provider&gt;
          &lt;jta-data-source&gt;java:jboss/datasources/cloudflow&lt;/jta-data-source&gt;
          &lt;properties&gt;
           &lt;!-- Properties for Hibernate --&gt;
           &lt;property name="hibernate.jdbc.batch_size" value="50"/&gt;  
           &lt;property name="hibernate.show_sql" value="false" /&gt;
           &lt;property name="hibernate.dialect" value="org.hibernate.dialect.MySQLInnoDBDialect" /&gt;  
          &lt;/properties&gt;
     &lt;/persistence-unit&gt;
  
  &lt;/persistence&gt;
  </code></pre>