title: EntityManager.find can't find entity, but using the Criteria API does
body: <p>I've encountered a rather odd case in Java EE 6 where using the JPA EntityManager's <code>find</code> method along with an entity's primary id returns null, but using the Criteria API to select all entities with that id works fine.</p>
  
  <p>Here is the code I'm using for <code>find</code>:</p>
  
  <pre><code>// Always returns null, even for records I know for sure are in there.
  user = em.find(User.class, userId);
  </code></pre>
  
  <p>...and here's the code I'm using with the Criteria API:</p>
  
  <pre><code>CriteriaBuilder builder = em.getCriteriaBuilder();
  CriteriaQuery&lt;User&gt; criteria = builder.createQuery(User.class);
  Root&lt;User&gt; u = criteria.from(User.class);
  TypedQuery&lt;User&gt; query = em.createQuery(
      criteria.select(u).where(builder.equal(u.get("id"), userId)));
  user = query.getSingleResult();
  </code></pre>
  
  <p>Any idea why <code>find</code> returns null but Criteria finds the User?  I tried these two alternate methods in the exact same spot in the program.</p>
  
  <p>Here are the relevant portions of the User entity:</p>
  
  <pre><code>@Entity
  @Table(name = "USERS")
  @Access(AccessType.PROPERTY)
  public class User implements Serializable {
      ...
      private Long id;
      ...
      @Id
      @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "user_id_generator")
      @SequenceGenerator(name = "user_id_generator", sequenceName = "user_sequence", allocationSize = 1)
      @Column(name="id")
      public Long getId() {
          return this.id;
      }
  
      public void setId(Long id) {
          this.id = id;
      }
      ...
  }
  </code></pre>