private void setPersistentEntityId(Object entity, String id) {
   PersistentProperty idProperty = getPersistentEntityFor(entity.getClass()).getIdProperty();
   // Only deal with String because ES generated Ids are strings !
   if (idProperty != null && idProperty.getType().isAssignableFrom(String.class)) {
     Method setter = idProperty.getSetter();
     if (setter != null) {
       try {
         setter.invoke(entity, id);
       } catch (Throwable t) {
         t.printStackTrace();
       }
     }
   }
 }
 private <T> void setPersistentEntityId(T result, String id, Class<T> clazz) {
   if (mappingContext != null && clazz.isAnnotationPresent(Document.class)) {
     PersistentProperty<ElasticsearchPersistentProperty> idProperty =
         mappingContext.getPersistentEntity(clazz).getIdProperty();
     // Only deal with String because ES generated Ids are strings !
     if (idProperty != null && idProperty.getType().isAssignableFrom(String.class)) {
       Method setter = idProperty.getSetter();
       if (setter != null) {
         try {
           setter.invoke(result, id);
         } catch (Throwable t) {
           t.printStackTrace();
         }
       }
     }
   }
 }