コード例 #1
0
 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();
       }
     }
   }
 }
コード例 #2
0
 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;
 }