title: Unexpected behaviour of EntityManager.merge()
body: <p>I am using embedded glassfish (3.1.2.2) with junit (4.11), with JDK 1.7, though my source and target is set to 1.6 (maven-compiler-plugin configuration).</p>
  
  <p>Following is my code:</p>
  
  <p><strong>Person.java</strong></p>
  
  <pre><code>@Entity
  public class Person implements Serializable {
  
      private static final long serialVersionUID = 81398385247591972L;
  
      @Id
      @GeneratedValue
      private Long id;
      @Version
      private Long version;
      @Column(length = 15, nullable = false, unique = true, updatable = false)
      private String username;
      @Column(length = 50)
      private String status;
  
      // Constructors
  
      // getters/setters
  
      // hashCode, equals, toString
  
  }
  </code></pre>
  
  <p><strong>Service.java</strong></p>
  
  <pre><code>@Stateless
  public class Service {
  
      @PersistenceContext(unitName = "ExamplePU", type = PersistenceContextType.TRANSACTION)
      private EntityManager em;
  
      public Person add(Person person) {
          em.persist(person);
          return person;
      }
  
      public Person find(Long id) {
          return em.find(Person.class, id);
      }
  
      public Person modify(Person person) {
          return em.merge(person);
      }
  
      // some more code ...
  
  }
  </code></pre>
  
  <p><strong>ServiceTest.java</strong></p>
  
  <pre><code>public class ServiceTest {
  
      private static EJBContainer ejbContainer;
      private static Service service;
  
      // @BeforeClass, @AfterClass, @Before, @After
  
      @Test
      public void testMerge() {
          Person person;
  
          /* Step 1 */person = service.add(new Person("username", "status"));
          print("Added : " + person);
  
          person.setStatus("Away");
          /* Step 2 */person = service.modify(person);
          print("Merged (status change) : " + person);
  
          person.setUsername("UsErNaMe");
          /* Step 3 */person = service.modify(person);
          print("Merged (username change) : " + person);
      }
  
      // Some more tests
  
  }
  </code></pre>
  
  <p><strong>Step 1</strong> generates following SQL (as expected):</p>
  
  <pre><code>INSERT INTO PERSON (ID, STATUS, USERNAME, VERSION) VALUES (?, ?, ?, ?)
      bind =&gt; [1, status, username, 1]
  </code></pre>
  
  <p><strong>Step 2</strong> generates following SQL (as expected):</p>
  
  <pre><code>UPDATE PERSON SET STATUS = ?, VERSION = ? WHERE ((ID = ?) AND (VERSION = ?))
      bind =&gt; [Away, 2, 1, 1]
  </code></pre>
  
  <p><strong>Step 3</strong> does not generate any SQL, but it does not throw any exception, which I am expecting, as the 'username' is annotated as <strong>@Column(..., updatable = false)</strong>. The print(...) method prints following output:</p>
  
  <blockquote>
    <p>Merged (username change) : Person [id=1, version=2, username=UsErNaMe, status=Away]</p>
  </blockquote>
  
  <p>This time the merge() operation has updated username, but not version. Also, now the database is out-of-sync with EntityManager cache.</p>
  
  <p>Is this expected, or bug in EclipseLink?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Expected result is exception at Step 3 above.</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Have filed bug <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=402109" rel="nofollow">here</a>.</p>