1 Reply Latest reply on Feb 22, 2005 10:06 AM by Bill Burke

    Lazy Initialization

    Florian Fray Newbie

      Hi folks!

      Im trying out the new EJB3.0 features of JBoss. While developing a small app for managing seminars I've tried let some relations being fetched lazily.
      A snippet of my db-structure contains this:
      Seminar - Speaker (Person): n to m
      Seminar - Manager (Person): n to m
      Seminar - Topic: 1 to m
      Seminar - Supplemental offers(Article): n to m
      Seminar - Execution Periods: 1 to m

      I put the getters for the related Sets in a Session-Bean, the client
      has to use it instead of invoking the getters of the Seminar-Object directly.
      So far so good.
      A session getter does nothing else then invoking the Seminars' getter,
      put the result in a new Set and return it.
      I've created some delegates for adding related objects, too.
      But these don't work if the used set isn't walked through once for initializing it.
      I expected the Set to get initialized by invoking the add method and afterwards doing what a honest "add" always does ;)
      Bug or feature? What's the way it's meant to be played?

      Thanks in advance

      Florian

        • 1. Re: Lazy Initialization
          Bill Burke Master

          There is no CMR in EJB 3.0. There is one "managing" side of the relationship. In ManyToMany this is defined by the mappedBy attribute. For OneToMany the owner is alwasy the ManyToOne side.

          So, for adding a topic, you'll have to do topic.setSeminar(this) within your "addTopic" method.

          To update the collection, you'll have to merge the seminar and the OneToMany will have to have a CASCADE MERGE, or just merge every topic you add to the seminar.