3 Replies Latest reply on Aug 20, 2005 8:19 PM by Emmanuel Bernard

    many-to-many initialization

    Zihong Lu Newbie

      For entity beans with many-to-many relationship, and lazy fetching strategy on both ends, how can I force initialization of the relationship in Java code, besides the "fetch join"?

      I tried to use BeanAObject.getBeanBList().size(), it did initialize half way, ie, the returned list has wrapped BeanB object, but the BeanB object states are not initialized, as described in this link


      so far I did not hear any answer. Sorry if this sounds like double posts, just want to make sure that I ask question to the point.


        • 1. Re: many-to-many initialization
          Emmanuel Bernard Master

          I've been a bit aggressive in my lazyness of many to many. I think I'm gonna relax that in the next release to allow objects to be initialized when the @ManyToMany collection is touched.

          Note that the spec allow such an aggressive lazy loading, so a code expecting to be portable should not rely on the object loading except if all the objects state are touched, a "fetch" keyword is used in HQL or the collection is marked as EAGER

          • 2. Re: many-to-many initialization
            Zihong Lu Newbie

            Thanks for the reply, and for relaxing the aggressive lazy loading of many-to-many in next release. I do think that the behavior should be consistent for both one-to-many and many-to-many, aggressive or not. Would you like me to enter an entry in JIRA? If so, is this a bug or a feature request?

            On a slightly different aspect, I think the spec needs to address the following:

            1. in entity manager, need a way for forced initialization of all relationships of a bean, one similar to Hibernate.initialize(parent).

            2. forced initialization of selected relationship. For example, entity A has a relationship with entity B as AB, and has a relationship with entity C as AC, it will be very convenient to have initialzing only relationship AB without initializing relationship AC. This is what my BeanAObject.getBeanBList().size() is intended to accomplish, and the behavior that Hibernate supports.

            The "fetch join" can do both. However, the pitfall of "fetch join" is that you are required to write bean specific HQL, while the 2 items that I mentioned don't.


            • 3. Re: many-to-many initialization
              Emmanuel Bernard Master

              I've fixed that already, so no need for JIRA issue.

              And please forward your proposals to ejb3-pdr-feedback@sun.com
              I basically agree with you.