3 Replies Latest reply on Dec 30, 2005 3:08 PM by epbernard

    change of subclasse causes error

    ruud1

      I have a baseclasse and several subclasses (A,B,C) all of them are saved in one table.

      I need to convert from one to another subclasse. Lets say from A to B.

      I have tried several things:

      1 : create a new instance of B, read A from the database and perform a merge. I got the error :
      A unexpected error : [javax.ejb.EJBException:null; CausedByException is:
      Object with id: null was not of the specified subclass: com.hollandhouse.unispool.entity.beans.LPRDevice (class of the given object did not match class of persistent copy)].

      2 : create a new instance of B, test whether the class of A and B are instanciated from different classes. If so : set B.id equal to A.id and persist. This also goes wrong.

      I dont like the solution : read A, copy every attribute to B, delete A, create B with the id of A. This has consequences for every relationship and several processes.

      Has anybody a suggestion ?

      With kind regards
      Ruud van Kersbergen

        • 1. Re: change of subclasse causes error
          epbernard

          this is not doable in Java (ie to change one class into another one), hence it's not possible in EJB3.

          • 2. Re: change of subclasse causes error
            ruud1

            i agree, but the problem is not creating the right subclasse in java (done by copying every attribute and/or using a special constructor).

            Suppose baseclasse X and subclasse A and B.

            I have a persistent object A, i create an object B with the SAME ID in A.

            The problem is that i can not persist object B without deleting A first.

            If i delete A and persist B in 1 transaction on what moment is the consistency checked by the application server (at the moment of delete of A or at the end of the transaction ?)

            • 3. Re: change of subclasse causes error
              epbernard

              I don't really understand your question, but your domain could probably be refactored (and benefit from it) wo using inheritance