code: public Query getPKQuery(Identity oid)
      {
          Object[] values = oid.getPrimaryKeyValues();
          ClassDescriptor cld = pb.getClassDescriptor(oid.getObjectsTopLevelClass());
          FieldDescriptor[] fields = cld.getPkFields();
          Criteria criteria = new Criteria();
  
          for (int i = 0; i < fields.length; i++)
          {
              FieldDescriptor fld = fields[i];
              criteria.addEqualTo(fld.getAttributeName(), values[i]);
          }
          return QueryFactory.newQuery(cld.getClassOfObject(), criteria);
      }
docs: Answer the primary key query to retrieve an Object
  
  @param oid the Identity of the Object to retrieve
  @return The resulting query