Cayenne
  1. Cayenne
  2. CAY-1503

POST_LOAD is not called on prefetched objects

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 3.0.1, 3.1M1
    • Fix Version/s: 3.0.2, 3.1M1
    • Component/s: Core Library
    • Labels:
      None

      Description

      Noticed that POST_LOAD is not invoked when an object was prefetched with another object. Here is a test case:

      + public void testPostLoad_Prefetch() throws Exception

      { + LifecycleCallbackRegistry registry = getDomain() + .getEntityResolver() + .getCallbackRegistry(); + + ObjectContext context = createDataContext(); + + registry.addListener(LifecycleEvent.POST_LOAD, Artist.class, "postLoadCallback"); + MockCallingBackListener listener = new MockCallingBackListener(); + registry.addListener( + LifecycleEvent.POST_LOAD, + Artist.class, + listener, + "publicCallback"); + + Artist a1 = context.newObject(Artist.class); + a1.setArtistName("XX"); + Painting p1 = context.newObject(Painting.class); + p1.setToArtist(a1); + p1.setPaintingTitle("XXX"); + context.commitChanges(); + + // reset context and read related object + context = createDataContext(); + + SelectQuery q = new SelectQuery(Painting.class); + q.addPrefetch(Painting.TO_ARTIST_PROPERTY); + p1 = (Painting) context.performQuery(q).get(0); + + // artist is prefetched here, and a callback must have been invoked + a1 = p1.getToArtist(); + assertEquals(PersistenceState.COMMITTED, a1.getPersistenceState()); + assertEquals(1, a1.getPostLoaded()); + assertSame(a1, listener.getPublicCalledbackEntity()); + }

        Activity

        No work has yet been logged on this issue.

          People

          • Assignee:
            Andrus Adamchik
            Reporter:
            Andrus Adamchik
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development