code: public static String prepareCompositeKey(final SingularAttribute attribute, final MetamodelImpl metaModel,
              final Object compositeKey)
      {
          Field[] fields = attribute.getBindableJavaType().getDeclaredFields();
          EmbeddableType embeddable = metaModel.embeddable(attribute.getBindableJavaType());
          StringBuilder stringBuilder = new StringBuilder();
  
          try
          {
              for (Field f : fields)
              {
                  if (!ReflectUtils.isTransientOrStatic(f))
                  {
                      if (metaModel.isEmbeddable(((AbstractAttribute) embeddable.getAttribute(f.getName()))
                              .getBindableJavaType()))
                      {
                          f.setAccessible(true);
                          stringBuilder.append(
                                  prepareCompositeKey((SingularAttribute) embeddable.getAttribute(f.getName()),
                                          metaModel, f.get(compositeKey))).append(LUCENE_COMPOSITE_KEY_SEPERATOR);
                      }
                      else
                      {
                          String fieldValue = PropertyAccessorHelper.getString(compositeKey, f);
                          fieldValue = fieldValue.replaceAll("[^a-zA-Z0-9]", "_");
  
                          stringBuilder.append(fieldValue);
                          stringBuilder.append(LUCENE_COMPOSITE_KEY_SEPERATOR);
                      }
                  }
              }
          }
          catch (IllegalAccessException e)
          {
              logger.error(e.getMessage());
          }
          catch (IllegalArgumentException e)
          {
              logger.error("Error during prepare composite key, Caused by {}.", e);
              throw new PersistenceException(e);
          }
  
          if (stringBuilder.length() > 0)
          {
              stringBuilder.deleteCharAt(stringBuilder.lastIndexOf(LUCENE_COMPOSITE_KEY_SEPERATOR));
          }
          return stringBuilder.toString();
      }
docs: Prepares composite key as a lucene key.
  
  @param m
  entity metadata
  @param metaModel
  meta model.
  @param compositeKey
  composite key instance
  @return redis key