users@glassfish.java.net

Re: exception inserted a deleted entity

From: <glassfish_at_javadesktop.org>
Date: Tue, 05 Jun 2007 09:06:25 PDT

inserting...

simple case below:

@Stateful
public class MyBean {
  @NamedQuery(name="deleteAll", query="delete from MyObj m");

  public void init(){
    MyObj o=new MyObj(1); // where MyObj is a class annotated with @Entity with a single value that is the primary key
    em.persist(o); // ***
  }

  public void myFunc(){
    // do something
  }

  void reset(){
    em.createNamedQuery("deleteAll").executeQuery();
    em.clear();
    em.flush();
  }
}



i then have an external app (some junit tests) that do this repeatedly.

init();
myFunc();
reset();


On the second pass it fails at the em. persist() with EntityExistsException even though the record isn't in the database, but is obviously still cached...
[Message sent by forum member 'jsl123' (jsl123)]

http://forums.java.net/jive/thread.jspa?messageID=220593