title: Statement was aborted because it would have caused a duplicate key value in a unique or primary key constraint
body: <p>Error while running the test. I get a <strong>SQLIntegrityConstraintViolationException</strong>.</p>
  
  <pre><code>Internal Exception: java.sql.SQLIntegrityConstraintViolationException: The statement was aborted because it would have caused a duplicate key value in a unique or primary key constraint or unique index identified by 'SQL160412141534310' defined on 'CHARACTERS'.
  </code></pre>
  
  <p>Code for Character class</p>
  
  <pre><code>@Entity
  @Table(name = "CHARACTERS")
  @NamedQueries({
  @NamedQuery(name = Character.FIND_ALL, query = "SELECT c FROM Character c")
  })
  public class Character implements Serializable {
  
  public static final String FIND_ALL = "Character.findAll";
  
  private static final long serialVersionUID = 1L;
  
  @Id 
  private int id;
  
  @Column(length = 50)
  private String name;
  
  public Character() {
  }
  
  public Character(int id, String name) {
      this.id = id;
      this.name = name;
  }
  
  public Character(String name) {
      this.name = name;
  }
  
  /* Getter and setter below */
  </code></pre>
  
  <p>CharactersBean class</p>
  
  <pre><code>@Stateful
  @TransactionAttribute(TransactionAttributeType.NEVER)
  public class CharactersBean implements Serializable {
  
  @PersistenceContext(type = PersistenceContextType.EXTENDED)
  EntityManager em;
  
  public void save(Character e) {
      em.persist(e);
  }
  
  @TransactionAttribute(TransactionAttributeType.REQUIRED)
  public void commitChanges() {
  
  }
  
  public List&lt;Character&gt; get() {
      return em.createNamedQuery(Character.FIND_ALL, Character.class).getResultList();
  }
  </code></pre>
  
  <p>Testing class
  When it executes the <strong>should_update_characters_after_transaction_flush</strong>, above exception is thrown.</p>
  
  <pre><code>@RunWith(Arquillian.class)
  public class ExtendedPersistenceContextTest {
  
  @PersistenceContext
  EntityManager em;
  
  @EJB
  CharactersBean bean;
  
  @Deployment
  public static WebArchive deploy() {
      return ShrinkWrap.create(WebArchive.class)
              .addPackage("org.javaee7.jpa.extended.pc")
              .addAsResource("META-INF/persistence.xml")
              .addAsResource("META-INF/create.sql")
              .addAsResource("META-INF/drop.sql")
              .addAsResource("META-INF/load.sql");
  }
  
  @Before
  public void setup() {
      Character wil = new Character(8, "Wil Wheaton");
      bean.save(wil);
  
      for (Character c : bean.get()) {
          if ("Raj".equals(c.getName())) {
              c.setName("Rajesh Ramayan");
              bean.save(c);
          }
      }
  }
  
  @Test
  @InSequence(1)
  public void should_not_persist_changes_without_transaction_flush() {
      List&lt;Character&gt; characters = em.createNamedQuery(Character.FIND_ALL, Character.class).getResultList();
      Character raj = em.find(Character.class, 6);
  
      assertThat(characters, hasSize(7));
      assertThat(raj.getName(), is(equalTo("Raj")));
  }
  
  @Test
  @InSequence(2)
  public void should_update_characters_after_transaction_flush() {
      //when
      bean.commitChanges();
  
      //then
      List&lt;Character&gt; characters = em.createNamedQuery(Character.FIND_ALL, Character.class).getResultList();
      Character rajesh = em.find(Character.class, 6);
      Character wil = em.find(Character.class, 8);
  
      assertThat(characters, hasSize(8));
      assertThat(rajesh.getName(), is(equalTo("Rajesh Ramayan")));
      assertThat(wil.getName(), is(equalTo("Wil Wheaton")));
  }
  </code></pre>
  
  <p>Data in enter in Derby database. </p>
  
  <pre><code>INSERT INTO CHARACTERS("ID", "NAME") VALUES (1, 'Penny')
  INSERT INTO CHARACTERS("ID", "NAME") VALUES (2, 'Sheldon')
  INSERT INTO CHARACTERS("ID", "NAME") VALUES (3, 'Amy')
  INSERT INTO CHARACTERS("ID", "NAME") VALUES (4, 'Leonard')
  INSERT INTO CHARACTERS("ID", "NAME") VALUES (5, 'Bernadette')
  INSERT INTO CHARACTERS("ID", "NAME") VALUES (6, 'Raj')
  INSERT INTO CHARACTERS("ID", "NAME") VALUES (7, 'Howard')
  </code></pre>