Uploaded image for project: 'Cayenne'
  1. Cayenne
  2. CAY-1503

POST_LOAD is not called on prefetched objects

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 3.0.1, 3.1M1
    • 3.0.2, 3.1M1
    • Core Library
    • 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()); + }

      Attachments

        Activity

          People

            andrus Andrus Adamchik
            andrus Andrus Adamchik
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: