title: Hibernate JPA : ignore wrong sql foreign key values
body: <p>I have a project to maintain, The persistance layer of this project uses <code>JPA</code> and <code>Hibernate</code> and it is running on a <code>MySQL</code> server, the database is not  <code>relational</code> and the engine is <code>MyISAM</code> on all tables.</p>
  
  <p>I have some foreignkey relationshps mapped as <code>@ManyToOne</code> relationship on my entities.</p>
  
  <p>Now the problem is that some of those columns are supposed to be <code>foreignkeys</code> in order to be mapped right, but they aren't (since the engine is <code>MyISAM</code>, and the <code>DB</code> is only <code>relational</code> on theory), some of these columns have wrong values like <strong>(negative ones -1 , 0 , inexistant dead parents)</strong>.</p>
  
  <pre><code>@Entity
  public class EntityA {
  
     @ManyToOne
     @JoinColumn(name="COL_FK")
     private EntityB b;
  
  }
  </code></pre>
  
  <p>In the DB, Possible values for <code>COL_FK</code> are : <code>0,-1,DEAD PARENTS</code></p>
  
  <p>I can't neither change the db structure nor edit the 
  the data within the columns.All I can do is change the code.</p>
  
  <p>How can I tell Hibernate to ignore those values and not throw a <code>RuntimeException</code> while I'm getting list just because one of its element contains a wrong <code>foreingkey</code> value.</p>
  
  <p>Thanks.</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <pre><code>@Embeddable
  public class EntityA {
      @ManyToOne()
      @JoinColumn(name = "idClient")
      @NotFound(action = NotFoundAction.IGNORE)
      private ClientBO idClient;
  
  }
  </code></pre>
  
  <p>StackTrace :</p>
  
  <pre><code>AVERTISSEMENT: org.springframework.orm.jpa.JpaObjectRetrievalFailureException: Unable to find xx.xxx.xx.xxx.ClientBO with id 210; nested exception is javax.persistence.EntityNotFoundException: Unable to find xx.xx.xx.xxx.ClientBO with id 210
  </code></pre>