public static <E extends Identifiable>E findByPrimaryKey(EntityManager em,BigInteger id,Class<E> type){
  requireArgument(em != null,"The entity manager cannot be null.");
  requireArgument(id != null && id.compareTo(ZERO) > 0,"ID cannot be null and must be positive and non-zero");
  requireArgument(type != null,"The entity type cannot be null.");
  TypedQuery<E> query=em.createNamedQuery("JPAEntity.findByPrimaryKey",type);
  query.setHint("javax.persistence.cache.storeMode","REFRESH");
  try {
    query.setParameter("id",id);
    query.setParameter("deleted",false);
    return query.getSingleResult();
  }
 catch (  NoResultException ex) {
    return null;
  }
}

public static < E extends Identifiable > E findByPrimaryKey ( EntityManager em , BigInteger id , Class < E > type ) { requireArgument ( em != null , "The entity manager cannot be null." ) ; requireArgument ( id != null && id . compareTo ( ZERO ) > 0 , "ID cannot be null and must be positive and non-zero" ) ; requireArgument ( type != null , "The entity type cannot be null." ) ; TypedQuery < E > query = em . createNamedQuery ( "JPAEntity.findByPrimaryKey" , type ) ; query . setHint ( "javax.persistence.cache.storeMode" , "REFRESH" ) ; try { query . setParameter ( "id" , id ) ; query . setParameter ( "deleted" , false ) ; return query . getSingleResult ( ) ; } catch ( NoResultException ex ) { return null ; } }
finds a jpa entity by its primary key .
