3 Replies Latest reply on Jan 12, 2007 2:35 PM by trashhash

    Simple remove wont work. Detached instance

    trashhash

      Hi, Im uable to remove an object/post from database by using EntityManager.remove(). The console says Removing a detached instance. But post remainsin db. Is it even possible to remove a detached object? Im not getting why its detached, my code is simple.

      User user = (User) service.getUserById(34);
      service.deleteUser(user);
      


      where would my session/EntityManager be lost?

      Thanks for your time.

        • 1. Re: Simple remove wont work. Detached instance
          alexg79

          Are you by any chance using "service" through a remote interface?
          Why do you need to cast the result to User btw? Does that method return other objects than Users?

          • 2. Re: Simple remove wont work. Detached instance
            trashhash

            Thansk for your reply. It turns out that the exception is thrown because the cascade option. This works fine.

            em.remove(em.merg(user));
            


            While

            em.remove(user);
            


            Dose not work because my User have an external reference to a Address. So bt deleting User it would like to also delete The Address.

            Now I would like to know who do I set the cascade option. So I can delete a Player without removing a Team. And vice versa.

            Thanks for your time.



            • 3. Re: Simple remove wont work. Detached instance
              trashhash

              Sorry for reposting, but Im not able to edit my post.

              To answer your question, yes Im using my service through remote interface. And casting is overflow, its always returning a user.

              I have look a bit more into CASCADE but Im only finding option for enable, not disable. So default should be disable? Why cant I cant I remove a simple Entity with no external reference?