title: EntityManager.persist() works, but EntityManager.merge() does not
body: <p>We are using EclipseLink 2.5.2 and WildFly 9.0.0.</p>
  
  <p>Here is a method that gets called a certain number of times every hour (specified by an EJB timer). For my testing purposes, I've changed it to fire off every minute, and in my specific configuration this method will get called 10 times per minute since there are 10 updates to be made:</p>
  
  <pre><code>@Stateless
  public class NetCentricDataService {
  
      @PersistenceContext(unitName = "NetCentricPersistenceUnit")
      private EntityManager em;
  
      public void insertUpdate(A a, B b, boolean insert) {
          if (insert) {
              em.persist(a);
              em.flush();
              if (b != null) {
                  em.persist(b);
                  em.flush();
              }
          } else {
              em.merge(a);
              if (b != null) {
                  em.merge(b);
              }
              em.flush();
          }
      }
  }
  </code></pre>
  
  <p>When I clear the tables associated with the two entity classes below, the <code>if(insert)</code> block executes, the <code>persist</code> calls work fine, and the DB is updated; however, if there are existing entries in the DB, the <code>else</code> block gets executed, the <code>merge</code> calls run with no <code>Exception</code>s, but the DB is not updated. I am checking this in SQL Developer after the method call is complete.</p>
  
  <p>EDIT: For example, the following does not work:</p>
  
  <pre><code>A a = dataService.getA(); // gets exisiting A from DB
  a.setSubject("My Subject");
  B b = dataService.getB(); // gets existing B from DB
  b.setFoo(123.45);
  insertUpdate(a, b, false);
  </code></pre>
  
  <p>Here is entity class A:</p>
  
  <pre><code>@Entity
  @Table(name = "A")
  @SuppressWarnings("unused")
  public class A implements Serializable {
  
      /**
       * Method called by container before DB insert.
       */
      @PrePersist
      public void beforeInsert() {
          if (objectType == null) {
              objectType = ObjectTypeEnum.UNKNOWN;
          }
      }
  
      @Id
      @Column(name = "MY_UID")
      private String myUid;
  
      @Column(name = "MY_NUMBER")
      private int myNumber;
  
      @Column(name = "SUBJECT")
      private String subject;
  
      @Enumerated(EnumType.ORDINAL)
      @Column(name = "OBJECT_TYPE")
      private ObjectTypeEnum objectType;
  
      // other columns, getters, setters, equals, etc.
  
  }
  </code></pre>
  
  <p>And here is entity class B:</p>
  
  <pre><code>@Entity
  @Table(name = "B")
  @SuppressWarnings("unused")
  public class B implements Serializable {
  
      @Id
      @Column(name = "MY_UID", nullable = false)
      private String myUid;
  
      @Column(name = "FOO")
      private double foo;
  
      @Column(name = "BAR")
      private double bar;
  }
  </code></pre>
  
  <p>Note: MY_UID in B is a foreign key for MY_UID in A.</p>
  
  <p>Note: There is no updatable=false property on any of the columns I'm trying to update.</p>
  
  <p>Let me know if there are any other files/methods/etc. I can include or if there is any more information I can provide. It is also worth noting that I do not maintain any of the code I posted, but I've been working with it recently. I asked the maintainer, and he said he wasn't sure why this was happening. Thanks in advance for any help!</p>
  
  <p>EDIT - Here is the datasources configuration from standalone-full.xml:</p>
  
  <pre><code>&lt;subsystem xmlns="urn:jboss:domain:datasources:3.0"&gt;
          &lt;datasources&gt;
              &lt;datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExampleDS" enabled="true" use-java-context="true"&gt;
                  &lt;connection-url&gt;jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE&lt;/connection-url&gt;
                  &lt;driver&gt;h2&lt;/driver&gt;
                  &lt;security&gt;
                      &lt;user-name&gt;sa&lt;/user-name&gt;
                      &lt;password&gt;****&lt;/password&gt;
                  &lt;/security&gt;
              &lt;/datasource&gt;
              &lt;datasource jta="true" jndi-name="java:jboss/datasources/SFDS" pool-name="SFDS" enabled="true" use-java-context="true" use-ccm="true"&gt;
                  &lt;connection-url&gt;jdbc:oracle:thin:@DB:1521:ORACLE_SID&lt;/connection-url&gt;
                  &lt;driver&gt;ojdbc6&lt;/driver&gt;
                  &lt;new-connection-sql&gt;select 1 from dual&lt;/new-connection-sql&gt;
                  &lt;pool&gt;
                      &lt;min-pool-size&gt;10&lt;/min-pool-size&gt;
                      &lt;max-pool-size&gt;100&lt;/max-pool-size&gt;
                      &lt;prefill&gt;false&lt;/prefill&gt;
                      &lt;use-strict-min&gt;false&lt;/use-strict-min&gt;
                      &lt;flush-strategy&gt;FailingConnectionOnly&lt;/flush-strategy&gt;
                  &lt;/pool&gt;
                  &lt;security&gt;
                      &lt;user-name&gt;wildfly_user&lt;/user-name&gt;
                      &lt;password&gt;****&lt;/password&gt;
                  &lt;/security&gt;
                  &lt;validation&gt;
                      &lt;check-valid-connection-sql&gt;select 1 from dual&lt;/check-valid-connection-sql&gt;
                      &lt;use-fast-fail&gt;true&lt;/use-fast-fail&gt;
                  &lt;/validation&gt;
              &lt;/datasource&gt;
              &lt;drivers&gt;
                  &lt;driver name="h2" module="com.h2database.h2"&gt;
                      &lt;xa-datasource-class&gt;org.h2.jdbcx.JdbcDataSource&lt;/xa-datasource-class&gt;
                  &lt;/driver&gt;
                  &lt;driver name="ojdbc6" module="com.oracle.jdbc"&gt;
                      &lt;xa-datasource-class&gt;oracle.jdbc.OracleDriver&lt;/xa-datasource-class&gt;
                  &lt;/driver&gt;
              &lt;/drivers&gt;
          &lt;/datasources&gt;
      &lt;/subsystem&gt;
  </code></pre>