title: JPA/Hibernate @NotFound Ignore not working if ID = 0
body: <p>I am having trouble with <code>JPA</code>. We have a database where not all foreign keys are consistent, so we use <code>@NotFound(Ignore)</code>, see code below. But sometimes it throws exceptions like:</p>
  
  <blockquote>
    <p>javax.persistence.EntityNotFoundException: Unable to find
    com.kiga.s3.domain.S3Image with id 0</p>
  </blockquote>
  
  <p>That happens only if the foreign key is <code>0</code> (if I change the id to <code>9999999</code> in the DB it works). What causes this behavior and what do I need to do to fix it? </p>
  
  <p>Here is our entity code</p>
  
  <pre><code>import org.hibernate.annotations.NotFound;
  import org.hibernate.annotations.NotFoundAction;
  @Entity
      public class KigaPageImage extends KigaEntityModel {
        @Column(name = "name")
        private String title;
        private String locale;
        private Long imageId;
  
        @ManyToOne
        @JoinColumn(name = "kigaPageID", referencedColumnName = "id")
        @NotFound(action = NotFoundAction.IGNORE)
        private KigaPage kigaPage;
  
        @ManyToOne
        @JoinColumn(name = "s3ImageID", referencedColumnName = "id")
        @NotFound(action = NotFoundAction.IGNORE)
        private S3Image s3Image;
  
        public S3Image getS3Image() {
          return s3Image;
        }
  
        public void setS3Image(S3Image s3Image) {
          this.s3Image = s3Image;
        }
      }
  </code></pre>
  
  <p>S3Image ID generation, does not have a connection to </p>
  
  <pre><code>@Entity
  public class S3Image{
    @Id
    @Column(name = "ID")
    @GeneratedValue
    private Long id;
  
    @Column(name = "URL")
    private String url;
  }
  </code></pre>
  
  <p>regards,
  Peter   </p>