Пример #1
0
  @Override
  public final T findFirstByProperty(
      final SingularAttribute<T, ? extends Object> property, final Object value) {
    final CriteriaQuery<T> criteriaQuery = criteriaBuilder.createQuery(getPersistentClass());
    final Root<T> root = criteriaQuery.from(getPersistentClass());
    criteriaQuery.select(root);
    final Predicate condition = criteriaBuilder.equal(root.get(property), value);
    criteriaQuery.where(condition);
    final TypedQuery<T> typedQuery = getEntityManager().createQuery(criteriaQuery);
    addCacheHints(typedQuery, "findFirstByProperty");

    final List<T> resultList = typedQuery.getResultList();

    if (resultList.isEmpty()) {
      return null;
    } else {
      return LoadHelper.recursiveInitialize(resultList.get(0));
    }
  }
Пример #2
0
 @Override
 public final T load(final I id) {
   return LoadHelper.recursiveInitialize(getEntityManager().find(getPersistentClass(), id));
 }