title: Why Lazy Fetching is not working JPA
body: <p>i have a hard time understanding the lazy fetching since i does not work for as i read about it in a book, they say that in lazy fetching jpa will load the entities only when they are accessed through geters so i created an Arquillian project to test this concept but it does not work.
  here are my two entities</p>
  
  <p><strong>Person</strong></p>
  
  <pre><code>package com.actionbazaar.model;
  
  @Entity
  @TableGenerator(
          initialValue = 5,
          name = "PERSON_SEQ",
          table = "PERSON_SEQ_TABLE",
          pkColumnName = "SEQ_NAME",
          pkColumnValue = "PERSON",
          valueColumnName = "SEQ_VALUE")
  public class Person implements Serializable {
  
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      private int id;
  
      private String fname;
      private String lname;
      @OneToMany(fetch = FetchType.LAZY, mappedBy = "owner", cascade = CascadeType.PERSIST)
      List&lt;Address&gt; addresses;
      //getters and setters 
  }
  </code></pre>
  
  <p><strong>Address</strong></p>
  
  <pre><code>    @Entity
  public class Address implements Serializable {
  
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      private int id;
      private String city;
      private String zip;
      private String street;
  
      @ManyToOne
      private Person owner;
  //getters and setters
  }
  </code></pre>
  
  <p>I have a stateless  session bean with this method</p>
  
  <pre><code>    public Person getFirstPerson() {
      Person p = em.find(Person.class, 1);
      em.detach(p);
      //why this call does not create an exception
      p.getAddresses().get(0);
      return p;
  }
  </code></pre>
  
  <p>since i detached the entity before accessing the address the addresses list should be empty and when i hace detached it so it is no longer managed by the entitymanager so i should not get addresses for the person 
  the problem is that i can fetch the addresses of that person even i have lazy fetch for addresses field and detached the entity before accessinbg the addresses field!!!!
  pleas some have the explanation .</p>
  
  <p><strong>An other test</strong></p>
  
  <pre><code>Person p= myStatlessSessionBean.getFirstPerson();
  myOtherStalessSesionBean.moveAllPeopleToCity("NY");
  if(p.getAddresses().get(0).getCity().equals("NY"))
  {
    system.out.prinln("person moved");
  }
  else {
  system.out.prinln("person did not move");
  } //prompts person did not move
  </code></pre>