Re: Bug in inheritance + callbacks?

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Tue Mar 30 2010 - 15:17:29 EDT

  • Next message: Andrus Adamchik: "Re: Generated Abstract Class"

    You are right about the problem though. While callbacks invocations
    are polymorphic (i.e. a concrete subclass' implementation will be
    invoked in runtime), callbacks "compilation" requires a method to be
    defined on a class that declares a callback. I guess this is (a) a bug
    and (b) a victim of us closely following the JPA spec that does not
    have a concept of a generation gap pattern.

    Andrus

    On Mar 30, 2010, at 9:57 PM, Andrus Adamchik wrote:

    > Not sure about the callback part, but using enum as a discriminator
    > is not yet supported:
    >
    > http://issues.apache.org/jira/browse/CAY-1213
    >
    > Andrus
    >
    > On Mar 30, 2010, at 6:52 PM, Michael Gentry wrote:
    >
    >> OK, this is kind of a followup on the generated abstract class...
    >>
    >> I'm attempting to test using inheritance with an enum as the
    >> discriminator column and a callback. For my classes:
    >>
    >> Product (Abstract) with Book and Game inheriting from Product.
    >>
    >> Product contains an enum (ProductType) to discriminate between the
    >> two.
    >>
    >> Product's post-add callback I set to "initializeProductType" and
    >> Cayenne generated this in _Product.java:
    >>
    >> protected abstract void initializeProductType();
    >>
    >> I had to go into Product.java and change that class to be abstract (I
    >> don't want any instances of it created). I implemented
    >> initializeProductType() in Book.java and Game.java (my only
    >> subclasses
    >> thus far). At runtime, I get this exception:
    >>
    >> Exception in thread "main" java.lang.IllegalArgumentException: Class
    >> mrg.model.Product has no valid callback method
    >> 'initializeProductType'
    >>
    >> Of course, this exception message is entirely true: Product does not
    >> contain initializeProductType() because it is in the subclasses.
    >>
    >> Thoughts on if this is legitimate?
    >>
    >> Thanks,
    >>
    >> mrg
    >>
    >> PS. The callback method implementation is:..verride protected void
    >> initializeProductType() { setProductType(ProductType.BOOK); } (for
    >> Book, of course).
    >>
    >
    >



    This archive was generated by hypermail 2.0.0 : Tue Mar 30 2010 - 15:18:15 EDT