JPA: Eclipselink не соблюдает em.remove()

Мне нужно удалить одну сущность и создать другую:

@Stateless
public class StatelessBean {
  @PersistenceUnit(unitName = "Unit001")
  EntityManagerFactory emf;

  protected void test() {
    EntityManager em = emf.createEntityManager();
    MyObj obj1 = em.find(MyObj.class, 100);
    MyObj obj2 = new MyObj();
    obj2.setKey("the same unique key as in obj1");
    em.remove(obj1);
    // em.flush(); 
    em.persist(obj2); // works fine when flush() is uncommented
    em.close();
  }
}

Если я оставлю em.flush()закомментированным, то я получу com.mysql .jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException(новые и старые объекты имеют одинаковое значение ключа)

В чем может быть причина такого ненормального поведения?

Сервер: Glassfish 3.1.2

Eclipse Persistence Services — 2.3.2.v20111125-r10461

persistence.xml:

<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0">
  <persistence-unit name="Unit001">
    <jta-data-source>jdbc/Unit001DS</jta-data-source>
    <properties>
      <property name="eclipselink.logging.level" value="INFO"/>
      <property name="eclipselink.target-database" value="MySQL"/>
    </properties>
  </persistence-unit>
</persistence>

Пул соединений:

${ASADMIN} --port ${DOMAIN_ADMIN_PORT}  create-jdbc-connection-pool --datasourceclassname com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource --restype javax.sql.ConnectionPoolDataSource --property "User=user:Password=pass:URL=jdbc\:mysql\://${DB_ADDRESS}/db" Unit001DS
${ASADMIN} --port ${DOMAIN_ADMIN_PORT}  create-jdbc-resource --connectionpoolid Unit001DS jdbc/Unit001DS
5
задан mispointer 12 April 2012 в 08:57
поделиться