4 Replies Latest reply on Jul 11, 2007 11:42 AM by waynebaylor

    what can be done for not real remove

      Hi,

      A person bean can have a set of phone beans. To delete a phone, code can be

      person.getPhones().remove(phone);
      //no entityManager.remove(phone);

      But how about if we don't want to delete the record from table, we just want that person doesn't have that phone.

      How does jboss 4.2 deal with such case?

      possible to introduce extra field indication whether or not the record is active, if it's not, jboss consider it not existed, but keeps the record's primary key preserved?

      Thanks

      John

        • 1. Re: what can be done for not real remove
          wolfgangknauf

          You remove the phone from the person's phone list, then save the person:

          person.getPhones().remove(phone);
          entityManager.merge (person);


          Hope this helps

          Wolfgang

          • 2. Re: what can be done for not real remove

             

            "Wolfgang Knauf" wrote:
            You remove the phone from the person's phone list, then save the person:

            person.getPhones().remove(phone);
            entityManager.merge (person);


            Hope this helps

            Wolfgang


            The API for merge is from http://www.hibernate.org/hib_docs/ejb3-api/
            merge(T entity)
            Merge the state of the given entity into the current persistence context.

            but how about restart jboss, will that person still have the "deleted" phone?

            • 3. Re: what can be done for not real remove
              alexg79

              Please post the code for the "person" entity. The key is how you defined the "phones" collection.

              • 4. Re: what can be done for not real remove
                waynebaylor

                i agree, if you have set CascadeType.ALL or CascadeType.REMOVE on the "phones" collection, then when you call

                person.getPhones().remove(phone)

                the phone will be removed from the db.

                if you only have CascadeType.PERSIST and/or CascadeType.MERGE, then only the "link" from person to that phone will be deleted--the phone entity will still be in the db.