Re: Making sense of callbacks

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Thu Nov 29 2007 - 07:22:32 EST

  • Next message: Michael Gentry: "Logging changes?"

    On Nov 29, 2007, at 10:56 AM, Aristedes Maniatis wrote:

    >>
    >> * prePersist() is only useful as a place to set object attributes
    >> (such as creationDate) since you cannot follow relations reliably
    >> in a ROP environment.

    True, and a workaround would be to support relationships for transient
    objects. Something Kevin was bringing up on multiple occasions.

    >> * postUpdate() and postPersist() are useful for changes which do
    >> not need to be committed atomically with the original commit. So
    >> good for creating log records, but not ideal for updating
    >> invoiceOwing.

    Another way to go about atomic commits is to set up a manual
    transaction that spans a request scope. I think that's an appropriate
    solution.

    >> * postPersist() is badly named. It is really postInsert()
    >> * we need preInsert()

    per JPA "persist" is "insert", so the naming is correct if somewhat
    confusing.

    > With some further reading of the JPA specification I have come to
    > the following conclusions:
    >
    > * the JPA was written by lawyers who get paid by the word

    It is confusing. Tell me about it! But partially because of
    differences in perception of persistence between Cayenne and the
    frameworks with EJB background.

    > * postPersist() is defined in the JPA to occur after a NEW record is
    > written to the database. Which is how Cayenne works.

    Yep.

    > * pre/postUpdate(): the JPA specification is very very unclear, but
    > it looks like maybe it might apply for both new and existing
    > records. But then postUpdate() overlaps postPersist() which is a bit
    > pointless.

    I think this is left up to implementation to handle. Yes - confusing.

    > * if preUpdate() is just for existing records we still need a
    > preInsert().

    I wonder if we should just call "preUpdate" for new objects in
    addition to prePersist.

    Andrus



    This archive was generated by hypermail 2.0.0 : Thu Nov 29 2007 - 07:23:05 EST