title: EntityNotFoundException in Hibernate Many To One mapping however data exist
body: <p>I am getting javax.persistence.EntityNotFoundException error when I am trying to get User through Invoice object</p>
  
  <p>invoice.getUser().getId()</p>
  
  <h2>Error is as follows</h2>
  
  <pre><code>javax.persistence.EntityNotFoundException: Unable to find com.indianretailshop.domain.User with id 5
      at org.hibernate.ejb.Ejb3Configuration$Ejb3EntityNotFoundDelegate.handleEntityNotFound(Ejb3Configuration.java:137)
      at org.hibernate.proxy.AbstractLazyInitializer.checkTargetState(AbstractLazyInitializer.java:189)
      at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:178)
      at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:215)
  </code></pre>
  
  <h2>Entity classes are as follows(getters and setters are not included)</h2>
  
  <pre><code>@Entity
  @Table(name="users")
  public class User implements Serializable {
      private static final long serialVersionUID = 1L;
  
      @Id
      @GeneratedValue(strategy=GenerationType.AUTO)
      @Column(unique=true, nullable=false)
      private int id;
  
      .
          .
          .
  
      //bi-directional many-to-one association to Invoice
      @OneToMany(mappedBy="user")
      private List&lt;Invoice&gt; invoices;
  }
  
  @Entity
  @Table(name="invoice")
  public class Invoice implements Serializable {
      private static final long serialVersionUID = 1L;
  
      @Id
      @GeneratedValue(strategy=GenerationType.AUTO)
      @Column(unique=true, nullable=false)
      private int id;
          .
          .
          .
  
      //bi-directional many-to-one association to User
      @ManyToOne(fetch=FetchType.LAZY)
      @JoinColumn(name="Users_id")
      private User user;
  }
  </code></pre>