title: JPA: Entity not created in the database by persist()
body: <p><strong>Code</strong></p>
  
  <p>My entity is defined like this:</p>
  
  <pre><code>@Entity(name="setting")
  @NamedQueries({ 
      @NamedQuery(name=JpaSetting.FIND_BY_NAME,
                  query="SELECT s FROM setting s WHERE s.name = :name"),
  })
  public class JpaSetting {
  
      // CONSTANTS \\
      protected static final String FIND_BY_NAME = "JpaSetting.findByName";
      protected static final String NAME_ATTR = "name";
  
      // FIELDS \\
      @Id @GeneratedValue(strategy=GenerationType.AUTO)
      @Column(name="id")
      private int m_id;
  
      @Column(name="name", nullable=false, unique=true)
      private String m_name;
  
      @Column(name="value")
      private String m_value;
  
      /* Classic getters and setters here... */
  }
  </code></pre>
  
  <p>The service is:</p>
  
  <pre><code>public class SettingsService {
      @PersistenceContext(type=PersistenceContextType.EXTENDED)
      private EntityManager m_em;
  
  
      private JpaSetting retrieveSetting(String p_name)
      throws NoResultException {
          return m_em.createNamedQuery(JpaSetting.FIND_BY_NAME, JpaSetting.class)
              .setParameter(JpaSetting.NAME_ATTR, p_name)
              .getSingleResult();
      }
  
      @Transactional
      public void save(String p_name, String p_value) {
          try {
              m_em.merge(
                  retrieveSetting(p_name).setValue(p_value) );
          }
          catch (NoResultException e) {
              m_em.persist(
                  new JpaSetting().setName(p_name).setValue(p_value) );
          }
      }
  }
  </code></pre>
  
  <p><strong>Problem:</strong> In the <code>save()</code>method, <code>m_em.persist()</code> does not create the entity in the database. The entity's id is generated (confirmed by debugging) and I can see the <code>select nextval('sequence')</code> request in Hibernate logs, but there is no create request.</p>
  
  <p>The table <code>setting</code> exists (created with the generated ddl) and is empty for now. I could insert and delete settings using the psql client with the same account as the application uses.</p>
  
  <p>No exception is thrown, everything seems to work normally.
  Except the entity is not persisted.</p>
  
  <p>I have another entity / service in the same application (using the same persistence unit) where the <code>persist()</code> works, but I can't find an obvious difference.</p>
  
  <p><strong>Edit:</strong>
  I just tried to create the record in the database to check the <code>merge</code> case, and it doesn't work either. So, it's a more general problem, but I don't understand where it lies.</p>