3 Replies Latest reply on Mar 30, 2011 9:10 PM by aupres

    EntityManager.remove() throws java.lang.IllegalArgumentException: Removing a detached instance ?

    aupres

      @Stateless

      public class LoginSession implements ILoginSession {

       

      @PersistenceContext(unitName="MyHome")

      EntityManager em;

      ....

      public Object loginFunc(Class clazz, Object primaryKey) {
        // TODO Auto-generated method stub
        return em.find(clazz, primaryKey);
      }

       

      public Object removeFunc(Serializable entity) {
        // TODO Auto-generated method stub
        em.remove(entity);
        return entity;
      }

       

      .....

      }

       

      bean codes are like above.

       

      in JSP file

       

      ILoginSession login = ctx.lookup(LoginSession/remote);

      Members erase = (Members)login.loginFunc(Members.class,"father");
      out.println(erase.toString()); // It works to this lines

      login.removeFunc(erase); // but this line thows Exception

       

      EntityManager.remove() fuction throws "java.lang.IllegalArgumentException: Removing a detached instance"

       

      I need your advice..

       

      Best Regards....^_^