2 Replies Latest reply on Sep 22, 2005 12:07 PM by ibsscott

    FetchType.LAZY

    ibsscott

      I'm not sure that FetchType.LAZY is working correctly or perhaps I do not fully understand how it works. I have an ejb with a OneToMany relationship. I really just want the relationship in order to use the Cascade capabilities and only fetch the relationship when I require it. I'm trying to create an xml document from the bean and do not necessarily want the relationships included.

      I saw that there was FetchType.LAZY bug recently fixed and I am using the CVS version which I downloaded on 9/20/2005.

      ...
       @OneToMany(cascade = CascadeType.REMOVE, fetch = FetchType.LAZY)
       @JoinColumn
       public List<EmployeeEJB> getEmployee() {
       return this._getEmployee();
       }
      ...


      When I fetch the ejb and try to marshall it into xml, the related beans are included in the output.

      CompanyEJB company = em.find(CompanyEJB.class, new String("1") );
       CompanyDocument companyDocument = objFactory2.createCompanyDocument();
       companyDocument.setCompany(company);
       Marshaller m = jc.createMarshaller();
       m.marshal(companyDocument, System.out);


      I thought perhaps the Marshaller was somehow retrieving the relationship so I cloned the bean prior to marshalling but I still get the relationships included in the output.

      CompanyEJB company = em.find(CompanyEJB.class, new String("1") );
      // clone
       CompanyEJB companyClone = (CompanyEJB) company.clone();
      //
       CompanyDocument companyDocument = objFactory2.createCompanyDocument();
       companyDocument.setCompany(companyClone);
       Marshaller m = jc.createMarshaller();
       m.marshal(companyDocument, System.out);

      Output:

      <company>
      ...
       <employee>
       <employeeName> employee name goes here </employeeName>
       </employee>
       <companyName> company name goes here </companyName>
      ...
      <company>


        • 1. Re: FetchType.LAZY
          skitching

          When you say "using the CVS version" do you mean the CVS version of Hibernate libs, of the hibernate-ejb-persistence libs, or of the jboss EJB3 libs?

          I *believe* the fix was in the jboss EJB layer, not in Hibernate itself.

          • 2. Re: FetchType.LAZY
            ibsscott

            The bug I was referring to was :

            http://jira.jboss.com/jira/browse/EJBTHREE-215

            Comment by Emmanuel Bernard [09/Sep/05 08:23 AM] [ Permlink ]
            Fixed in Hibernate CVS

            I downloaded the jboss-head CVS version EJB3 5.0-Alpha AS assuming this would have the hibernate fix in it. Is this not so and if not how long until it would be deployed with the Application Server? I'm not sure I would be able to retrofit other changes.