title: EJB Exception - An attempt was made to traverse a relationship using indirection that had a null Session.
body: <p>This is not a new exception. I went through lot of forum posts in stack overflow and understand why this is happening. But I need help in resolving my issue. </p>
  
  <p>I have two entity beans Equipment class and Equipment.  Following is the code. </p>
  
  <pre><code>public class EquipmentClass implements Serializable {
      private static final long serialVersionUID = 1L;
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      @Basic(optional = false)
      @Column(name = "id")
      private Integer id;
      @Basic(optional = false)
      @Column(name = "class_name")
      private String className;
      @Column(name = "description")
      private String description;
      @OneToMany(cascade = CascadeType.ALL, mappedBy = "equipmentClass")
      private Collection&lt;Equipment&gt; equipmentCollection;
  
      // getter and setter methods
   } 
  
  
  public class Equipment implements Serializable {
      private static final long serialVersionUID = 1L;
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      @Basic(optional = false)
      @Column(name = "id")
      private Integer id;
      @Basic(optional = false)
      @Column(name = "created_on")
      @Temporal(TemporalType.TIMESTAMP)
      private Date createdOn;
      @Basic(optional = false)
      @Column(name = "updated_on")
      @Temporal(TemporalType.TIMESTAMP)
      private Date updatedOn;
      @JoinColumn(name = "equipment_class", referencedColumnName = "id")
      @ManyToOne(optional = false)
      private EquipmentClass equipmentClass;
  
      // setter and getter methods 
  
  }
  </code></pre>
  
  <p>During adding an equipment, I set equipment class and persist it using <code>equipmentFacade.create(equipment);</code>  ( which persist the entity )</p>
  
  <pre><code>  EquipmentClass ec = equipment.getEquipmentClass();   
   &gt;&gt;&gt; ec.getEquipmentCollection().add(equipment); &lt;&lt; 
    equipmentClassFacade.edit(ec);
  </code></pre>
  
  <p>I get exception in the marked ( >> &lt; )  line above.</p>
  
  <p>As explained <a href="http://itechnicalvault.blogspot.co.uk/2012/04/java-ejb-exception-while-trying-to.html" rel="nofollow">here</a> , I tried to do <code>ec.getEquipmentCollection().size();</code>. But I get exception there. </p>
  
  <p>How should I proceed ?  Any help is much appreciated. </p>