title: JPA/Hibernate LEFT JOIN FETCH Lazy Exception because joined Entity is Null
body: <p>I have the folowing JPA query:</p>
  
  <pre><code>SELECT emp FROM Employee emp LEFT JOIN FETCH emp.supervisor WHERE emp.supervisor_id = :id_number
  </code></pre>
  
  <p>Employee data is structured as follows:</p>
  
  <pre><code>employee_ id, first_name, last_name, supervisor_id
             1,       jeff,     jones,             2
             2,        bob,     smith,             3
   etc...
  </code></pre>
  
  <p>where supervisor id is recursive to id of the same table.   The problem is ocassionally I'll get </p>
  
  <pre><code> org.hibernate.LazyInitializationException: could not initialize proxy - no Session
  </code></pre>
  
  <p>on the following EL call</p>
  
  <pre><code>#{employee.supervisor.last_name} 
  </code></pre>
  
  <p>because the data I am using, which is read-only, will have anomalies such as the employee has a supervisor_id on their record, but that employee_id has yet to have been inserted into the system or has been filtered out of the Oracle View that I am allowed to attached my Employee Entity to.</p>
  
  <pre><code>employee_ id, first_name, last_name, supervisor_id
             4,       jane,     dean,          9999
  where employee_id 9999 doesn't exist in my read-only data feed
  </code></pre>
  
  <p>what I really want is to still grab the Employee Entity but just populate a Null or Empty Supervisor.  </p>
  
  <p>Originally I had annotated my Employee Entity with <code>@NotFound(action = NotFoundAction.IGNORE)</code> on the supervisor field but that caused the Entity Manager to generate a ton of SQL call degregating the applications performance.  <a href="https://stackoverflow.com/questions/28546577/jpa-hibernate-query-slow-with-too-many-queries">JPA/Hibernate Query Slow with too many queries</a></p>
  
  <pre><code>@Entity
  Employee
  
  @OneToOne(fetch = FetchType.LAZY)
  //Removed  @NotFound(action = NotFoundAction.IGNORE)
  @JoinColumn(name = "supervisor_id", insertable = false, updatable = false)
  private Employee supervisor;
  </code></pre>
  
  <p>Am I missing some constructor on my Employee entity which will populate an empty Supervisor or is there some modification to my query which will perform the <code>IGNORE</code> as the annotation did, without a ton of individual SQL calls?</p>