code: public <T extends HistoricalEntity<?>, Y> T getCurrentUniqueByAttribute(
              Class<T> historicalEntityCls, 
              SingularAttribute<T, Y> attribute, Y value) {
          EntityManager entityManager = this.entityManagerProvider.get();
          CriteriaBuilder builder = entityManager.getCriteriaBuilder();
          CriteriaQuery<T> criteriaQuery = builder.createQuery(historicalEntityCls);
          Root<T> root = criteriaQuery.from(historicalEntityCls);
          Predicate whereClause = builder.and(
                  builder.equal(root.get(attribute), value),
                  expiredAt(root, builder));
          criteriaQuery.where(whereClause);
          TypedQuery<T> query = entityManager.createQuery(criteriaQuery);
          T result = null;
          try {
              result = query.getSingleResult();
          } catch (NonUniqueResultException nure) {
              LOGGER.warn("Result not unique for {}: {} = {}",
                      historicalEntityCls.getName(), attribute.getName(), value);
              result = query.getResultList().get(0);
          } catch (NoResultException nre) {
              LOGGER.debug("Result not existant for {}: {} = {}",
                      historicalEntityCls.getName(), attribute.getName(), value);
          }
          return result;
      }
docs: Gets the instance of the specified historical entity in the database
  that has the given value of the given attribute.
  
  @param <T> the type of the entity.The entity must be a subtype of
  {@link HistoricalEntity}. Cannot be <code>null</code>.
  @param <Y> the attribute's type.
  @param historicalEntityCls the class of the specified historical entity.
  @param attribute the attribute. Cannot be <code>null</code>.
  @param value the value. Cannot be <code>null</code>.
  
  @return the instance requested. Guaranteed not <code>null</code>.