Cayenne
  1. Cayenne
  2. CAY-1625

Transient objects do not work in ROP apps

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 3.1B1
    • Fix Version/s: 3.1B1
    • Component/s: ROP
    • Labels:
    • Environment:
      Mac 10.6

      Description

      In addition the problem referenced in CAY-1624, transient objects don't work when using ROP because in the client template the relationship values (to-one and to-many) are null and are only initialized to non-null values when they are added to an ObjectContext. By modifying the template to initialize the relationship values to something non-null, transient objects can be worked with locally (but not still saved?). I don't know if that is the best solution, but here's basically what I did.

        Activity

        Hide
        Olga Tkacheva added a comment -

        fixed

        Show
        Olga Tkacheva added a comment - fixed
        Hide
        Olga Tkacheva added a comment -

        I applied patch by Andrus. I run all test and got successfull results.

        Show
        Olga Tkacheva added a comment - I applied patch by Andrus. I run all test and got successfull results.
        Hide
        Andrus Adamchik added a comment -

        Attaching a reworked patch based on John's. Changes:

        1. Undid some new formatting so that the actual logic changes are more clear.

        2. Removed an additional strategy change not directly related to handling of transients - the 'safeEquals' check. This is not necessarily wrong, just an unrelated aspect requiring its own discussion.

        I am not applying the patch yet, as we'll need to ensure that all our client test cases are switched to the new format and all the tests pass. Anybody feel free to perform this work and create an extra patch here.

        Show
        Andrus Adamchik added a comment - Attaching a reworked patch based on John's. Changes: 1. Undid some new formatting so that the actual logic changes are more clear. 2. Removed an additional strategy change not directly related to handling of transients - the 'safeEquals' check. This is not necessarily wrong, just an unrelated aspect requiring its own discussion. I am not applying the patch yet, as we'll need to ensure that all our client test cases are switched to the new format and all the tests pass. Anybody feel free to perform this work and create an extra patch here.
        Hide
        John Huss added a comment -

        Revised template patch

        Show
        John Huss added a comment - Revised template patch
        Hide
        John Huss added a comment -

        Hmm. I actually have transient objects working completely on the server in my project. They can be used outside of an ObjectContext and then later be added to an ObjectContext and saved. My entities are PersistentObject subclasses with a custom template that initializes the relationship fields if needed (as attached), and includes calls to objectContext.propertyChanged in the accessors in the same way CayenneDataObject does before setting the value.

        So it looks like the propertyChanged call is necessary too - I've revised the attached template accordingly and I'm re-attaching it.

        Show
        John Huss added a comment - Hmm. I actually have transient objects working completely on the server in my project. They can be used outside of an ObjectContext and then later be added to an ObjectContext and saved. My entities are PersistentObject subclasses with a custom template that initializes the relationship fields if needed (as attached), and includes calls to objectContext.propertyChanged in the accessors in the same way CayenneDataObject does before setting the value. So it looks like the propertyChanged call is necessary too - I've revised the attached template accordingly and I'm re-attaching it.
        Hide
        Andrus Adamchik added a comment -

        Yes, this is known behavior of Cayenne - you can work with relationships only when you register an object with the context (ROP or server side, all the same). I suspect fixing it might be a bit more involved.

        Show
        Andrus Adamchik added a comment - Yes, this is known behavior of Cayenne - you can work with relationships only when you register an object with the context (ROP or server side, all the same). I suspect fixing it might be a bit more involved.
        Hide
        John Huss added a comment -

        Patch

        Show
        John Huss added a comment - Patch

          People

          • Assignee:
            Olga Tkacheva
            Reporter:
            John Huss
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Time Tracking

              Estimated:
              Original Estimate - 72h
              72h
              Remaining:
              Remaining Estimate - 72h
              72h
              Logged:
              Time Spent - Not Specified
              Not Specified

                Development