title: OneToOne + No Foreginkey + Unidirectional + Datamissing => EntityNotFoundException
body: <p>From a legacy system, we have 1 table (Entity) and 1 view (UserDetail) with no constraints but with relations.</p>
  
  <pre><code>Entity
  | Id | Desc | Created_By |...
  
  UserDetail
  | UserId | F_Name | L_Name |...
  </code></pre>
  
  <p>CreatedBy has the userid of the user who created that entity. We have a unidirectional mapping in Entity.java like below.</p>
  
  <pre><code>@OneToOne
  @JoinColumn(name = "CREATED_BY", referencedColumnName = "USER_ID")
  private UserDetail createdBy;
  </code></pre>
  
  <p><strong>Problem</strong></p>
  
  <p>But since its a legacy system, we don't have control on that and an user is hard deleted.</p>
  
  <p>When the entityReposity.findAll is called, following error is thrown</p>
  
  <pre><code>org.springframework.orm.jpa.JpaObjectRetrievalFailureException: Unable to find com...UserDetail with id 92237; nested exception is javax.persistence.EntityNotFoundException: Unable to find com...UserDetail with id 92237
  </code></pre>
  
  <p><strong>Question</strong></p>
  
  <p>How to make the JPA consider this association is optional or is there any way in JPA to make it ignore (like @NotFound in Hibernate)?</p>
  
  <p><strong>Tried</strong></p>
  
  <ol>
  <li><p>@NotFound works, but we need to hack @OneToOne as @ManyToOne. Also we want an implementation independent solution.
  Noticed this bug too, <a href="https://hibernate.atlassian.net/browse/ANN-725" rel="nofollow noreferrer">https://hibernate.atlassian.net/browse/ANN-725</a></p></li>
  <li><p>optional=true  -  If this would have worked as per the syntactical meaning on how it should behave, I wouldn't have written this.</p></li>
  <li><p>Also tried the postLoad() in UserDetails.java.</p></li>
  <li><p><a href="https://stackoverflow.com/questions/12261579/how-solve-javax-persistence-entitynotfoundexception-with-jpa-not-by-using-notf">@PostLoad solution</a> We have aop exceptionhandler and exception is caught there before @PostLoad in Entity class gets called. </p></li>
  </ol>
  
  <p>In Entity.java</p>
  
  <pre><code>    @PostLoad
      public void postLoad(){
          try {
              System.out.println(this.getCreatedBy()); //Before control comes here, it goes to aop exception handler
          }
          catch (EntityNotFoundException e){
              setCreatedBy(null);   
          }
      }
  </code></pre>
  
  <p>Any help would be appreciated.</p>