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 String getPersistentEntityId(Object entity) {
   PersistentProperty idProperty = getPersistentEntityFor(entity.getClass()).getIdProperty();
   if (idProperty != null) {
     Method getter = idProperty.getGetter();
     if (getter != null) {
       try {
         Object id = getter.invoke(entity);
         if (id != null) {
           return String.valueOf(id);
         }
       } catch (Throwable t) {
         t.printStackTrace();
       }
     }
   }
   return null;
 }