1 Reply Latest reply on May 24, 2005 5:28 AM by Emmanuel Bernard

    OneToOne LAZY bug

    manica Newbie

      I believe there may be a bug in the Lazy fetching of a OneToOne relationship. In preview 5, it appears that lazy loading and eager loading of a OneToOne does the same thing. Both are eager loaded, regardless of the FetchType specified on the relationship. I've attached a patch to the tutorial to show the issue. Notice that the address.getStreet() is available (outside the transaction) even though it is supposed to be lazy loaded.

      The patch can be applied as follows:


      cd jboss-EJB-3.0_Preview_5/docs/tutorial/relationships
      patch -p0 < relationships.patch



      Darin

      diff -Naur ../relationships-original/src/org/jboss/tutorial/relationships/bean/Customer.java ./src/org/jboss/tutorial/relationships/bean/Customer.java
      --- ../relationships-original/src/org/jboss/tutorial/relationships/bean/Customer.java 2005-05-23 17:08:17.000000000 +0000
      +++ ./src/org/jboss/tutorial/relationships/bean/Customer.java 2005-05-23 17:01:40.000000000 +0000
      @@ -55,7 +55,7 @@
       name = string;
       }
      
      - @OneToOne(cascade = {CascadeType.ALL})
      + @OneToOne(cascade = {CascadeType.ALL}, fetch = FetchType.LAZY)
       @JoinColumn(name = "ADDRESS_ID")
       public Address getAddress()
       {
      diff -Naur ../relationships-original/src/org/jboss/tutorial/relationships/bean/EntityTestBean.java ./src/org/jboss/tutorial/relationships/bean/EntityTestBean.java
      --- ../relationships-original/src/org/jboss/tutorial/relationships/bean/EntityTestBean.java 2005-05-23 17:08:17.000000000 +0000
      +++ ./src/org/jboss/tutorial/relationships/bean/EntityTestBean.java 2005-05-23 16:58:33.000000000 +0000
      @@ -66,6 +66,7 @@
       address.setCity("Billerica");
       address.setState("MA");
       address.setZip("02116");
      + molly.setAddress(address);
       customers2.add(molly);
      
       firstOne.setCustomers(customers1);
      diff -Naur ../relationships-original/src/org/jboss/tutorial/relationships/client/Client.java ./src/org/jboss/tutorial/relationships/client/Client.java
      --- ../relationships-original/src/org/jboss/tutorial/relationships/client/Client.java 2005-05-23 17:08:17.000000000 +0000
      +++ ./src/org/jboss/tutorial/relationships/client/Client.java 2005-05-23 16:56:17.000000000 +0000
      @@ -34,6 +34,7 @@
       for (Customer c : one.getCustomers())
       {
       System.out.println(c.getName());
      + System.out.println("Street address: " + c.getAddress().getStreet());
      
       }
       System.out.println("USAir customers");
      @@ -41,6 +42,7 @@
       for (Customer c : two.getCustomers())
       {
       System.out.println(c.getName());
      + System.out.println("Street address: " + c.getAddress().getStreet());
       }
      
       }