Example usage for org.hibernate.criterion Restrictions isNull

List of usage examples for org.hibernate.criterion Restrictions isNull

Introduction

In this page you can find the example usage for org.hibernate.criterion Restrictions isNull.

Prototype

public static Criterion isNull(String propertyName) 

Source Link

Document

Apply an "is null" constraint to the named property

Usage

From source file:mx.edu.um.mateo.activos.dao.impl.ActivoDaoHibernate.java

License:Open Source License

@Override
@SuppressWarnings("unchecked")
@Transactional(readOnly = true)/*from   ww  w  .j  ava 2 s. c  o  m*/
public Map<String, Object> depreciacionAcumuladaPorCentroDeCostoDetalle(Map<String, Object> params) {
    MathContext mc = new MathContext(16, RoundingMode.HALF_UP);
    Map<String, BigDecimal> totales = new HashMap<>();
    totales.put("ACUMULADA", BigDecimal.ZERO);
    totales.put("MENSUAL", BigDecimal.ZERO);
    totales.put("ANUAL", BigDecimal.ZERO);
    totales.put("NETO", BigDecimal.ZERO);
    Usuario usuario = (Usuario) params.get("usuario");
    String centroCostoId = (String) params.get("centroCostoId");
    Date fecha = (Date) params.get("fecha");
    CCostoPK ccostoPK = new CCostoPK(usuario.getEjercicio(), centroCostoId);
    CentroCosto centroCosto = (CentroCosto) currentSession().get(CentroCosto.class, ccostoPK);
    params.put("centroCosto", centroCosto);
    Criteria criteria = currentSession().createCriteria(Activo.class);
    criteria.add(Restrictions.eq("empresa.id", usuario.getEmpresa().getId()));
    criteria.add(Restrictions.eq("centroCosto.id.ejercicio.id.idEjercicio",
            usuario.getEjercicio().getId().getIdEjercicio()));
    criteria.add(Restrictions.eq("centroCosto.id.ejercicio.id.organizacion.id",
            usuario.getEjercicio().getId().getOrganizacion().getId()));
    criteria.add(Restrictions.eq("centroCosto.id.idCosto", centroCostoId));
    criteria.add(Restrictions.le("fechaCompra", fecha));
    criteria.add(Restrictions.isNull("fechaReubicado"));
    List<Activo> activos = criteria.list();
    for (Activo activo : activos) {
        log.trace("Depreciando activo {}", activo.getId());
        activo = this.deprecia(activo, fecha);

        this.depreciacionAcumuladaPorCentroDeCostoDetalle(activo, mc, totales);
    }

    // busca reubicados
    Query query = currentSession().createQuery(
            "select a from ReubicacionActivo ra inner join ra.activo a where ra.empresa.id = :empresaId and (ra.centroCosto.id.idCosto = :centroCostoId or ra.centroCostoAnterior.id.idCosto = :centroCostoId) and a.fechaCompra < :fecha group by a");
    query.setLong("empresaId", usuario.getEmpresa().getId());
    query.setString("centroCostoId", centroCostoId);
    query.setDate("fecha", fecha);
    List<Activo> reubicados = query.list();
    for (Activo activo : reubicados) {
        log.trace("Depreciando reubicado {}", activo.getId());
        query = currentSession().createQuery(
                "select r from ReubicacionActivo r where r.activo.id = :activoId order by r.fecha");
        query.setLong("activoId", activo.getId());
        List<ReubicacionActivo> reubicaciones = query.list();
        Date fechaAnterior = null;
        boolean bandera1 = true;
        for (ReubicacionActivo reubicacion : reubicaciones) {
            boolean seDeprecio = false;
            if (reubicacion.getFecha().before(fecha)
                    && reubicacion.getCentroCostoAnterior().getId().getIdCosto().equals(centroCostoId)) {
                if (fechaAnterior != null) {
                    activo.setFechaCompra(fechaAnterior);
                }
                activo.setCentroCosto(reubicacion.getCentroCostoAnterior());
                this.deprecia(activo, reubicacion.getFecha());
                activos.add(activo);
                seDeprecio = true;
            } else if (reubicacion.getCentroCostoAnterior().getId().getIdCosto().equals(centroCostoId)) {
                if (fechaAnterior != null) {
                    activo.setFechaCompra(fechaAnterior);
                }
                activo.setCentroCosto(reubicacion.getCentroCostoAnterior());
                this.deprecia(activo, fecha);
                activos.add(activo);
                seDeprecio = true;
                bandera1 = false;
            } else {
                activo.setCentroCosto(reubicacion.getCentroCostoAnterior());
            }
            fechaAnterior = reubicacion.getFecha();

            if (seDeprecio) {
                this.depreciacionAcumuladaPorCentroDeCostoDetalle(activo, mc, totales);
            }
        }

        if (bandera1 && activo.getCentroCosto().getId().getIdCosto().equals(centroCostoId)) {
            activo.setFechaCompra(activo.getFechaReubicado());
            this.deprecia(activo, fecha);
            activos.add(activo);
            this.depreciacionAcumuladaPorCentroDeCostoDetalle(activo, mc, totales);
        }

    }
    params.put("activos", activos);
    params.put("totales", totales);
    return params;
}

From source file:mx.edu.um.mateo.activos.dao.impl.ActivoDaoHibernate.java

License:Open Source License

@Override
@SuppressWarnings("unchecked")
@Transactional(readOnly = true)//from www . j a  v  a  2 s . com
public Map<String, Object> depreciacionMensualPorCentroDeCostoDetalle(Map<String, Object> params) {
    MathContext mc = new MathContext(16, RoundingMode.HALF_UP);
    Map<String, BigDecimal> totales = new HashMap<>();
    totales.put("ACUMULADA", BigDecimal.ZERO);
    totales.put("MENSUAL", BigDecimal.ZERO);
    totales.put("ANUAL", BigDecimal.ZERO);
    totales.put("NETO", BigDecimal.ZERO);
    Usuario usuario = (Usuario) params.get("usuario");
    String centroCostoId = (String) params.get("centroCostoId");
    Date fecha = (Date) params.get("fecha");
    CCostoPK ccostoPK = new CCostoPK(usuario.getEjercicio(), centroCostoId);
    CentroCosto centroCosto = (CentroCosto) currentSession().get(CentroCosto.class, ccostoPK);
    params.put("centroCosto", centroCosto);
    Criteria criteria = currentSession().createCriteria(Activo.class);
    criteria.add(Restrictions.eq("empresa.id", usuario.getEmpresa().getId()));
    criteria.add(Restrictions.eq("centroCosto.id.ejercicio.id.idEjercicio",
            usuario.getEjercicio().getId().getIdEjercicio()));
    criteria.add(Restrictions.eq("centroCosto.id.ejercicio.id.organizacion.id",
            usuario.getEjercicio().getId().getOrganizacion().getId()));
    criteria.add(Restrictions.eq("centroCosto.id.idCosto", centroCostoId));
    criteria.add(Restrictions.le("fechaCompra", fecha));
    criteria.add(Restrictions.isNull("fechaReubicado"));
    List<Activo> activos = criteria.list();
    for (Activo activo : activos) {
        log.trace("Depreciando activo {}", activo.getId());
        activo = this.deprecia(activo, fecha);

        this.depreciacionMensualPorCentroDeCostoDetalle(activo, mc, totales);
    }

    // busca reubicados
    Query query = currentSession().createQuery(
            "select a from ReubicacionActivo ra inner join ra.activo a where ra.empresa.id = :empresaId and (ra.centroCosto.id.idCosto = :centroCostoId or ra.centroCostoAnterior.id.idCosto = :centroCostoId) and a.fechaCompra < :fecha group by a");
    query.setLong("empresaId", usuario.getEmpresa().getId());
    query.setString("centroCostoId", centroCostoId);
    query.setDate("fecha", fecha);
    List<Activo> reubicados = query.list();
    for (Activo activo : reubicados) {
        log.trace("Depreciando reubicado {}", activo.getId());
        query = currentSession().createQuery(
                "select r from ReubicacionActivo r where r.activo.id = :activoId order by r.fecha");
        query.setLong("activoId", activo.getId());
        List<ReubicacionActivo> reubicaciones = query.list();
        Date fechaAnterior = null;
        boolean bandera1 = true;
        for (ReubicacionActivo reubicacion : reubicaciones) {
            boolean seDeprecio = false;
            if (reubicacion.getFecha().before(fecha)
                    && reubicacion.getCentroCostoAnterior().getId().getIdCosto().equals(centroCostoId)) {
                if (fechaAnterior != null) {
                    activo.setFechaCompra(fechaAnterior);
                }
                activo.setCentroCosto(reubicacion.getCentroCostoAnterior());
                this.deprecia(activo, reubicacion.getFecha());
                activos.add(activo);
                seDeprecio = true;
            } else if (reubicacion.getCentroCostoAnterior().getId().getIdCosto().equals(centroCostoId)) {
                if (fechaAnterior != null) {
                    activo.setFechaCompra(fechaAnterior);
                }
                activo.setCentroCosto(reubicacion.getCentroCostoAnterior());
                this.deprecia(activo, fecha);
                activos.add(activo);
                seDeprecio = true;
                bandera1 = false;
            } else {
                activo.setCentroCosto(reubicacion.getCentroCostoAnterior());
            }
            fechaAnterior = reubicacion.getFecha();

            if (seDeprecio) {
                this.depreciacionMensualPorCentroDeCostoDetalle(activo, mc, totales);
            }
        }

        if (bandera1 && activo.getCentroCosto().getId().getIdCosto().equals(centroCostoId)) {
            activo.setFechaCompra(activo.getFechaReubicado());
            this.deprecia(activo, fecha);
            this.depreciacionMensualPorCentroDeCostoDetalle(activo, mc, totales);
            activos.add(activo);
        }

    }
    params.put("activos", activos);
    params.put("totales", totales);
    return params;
}

From source file:mx.edu.um.mateo.inventario.dao.impl.ProductoDaoHibernate.java

License:Open Source License

@Override
@Transactional(readOnly = true)/*  w  w w .  j a  va2 s .c om*/
public Map<String, Object> lista(Map<String, Object> params) {
    log.debug("Buscando lista de productos con params {}", params);
    if (params == null) {
        params = new HashMap<>();
    }

    if (!params.containsKey("max")) {
        params.put("max", 10);
    } else {
        params.put("max", Math.min((Integer) params.get("max"), 100));
    }

    if (params.containsKey("pagina")) {
        Long pagina = (Long) params.get("pagina");
        Long offset = (pagina - 1) * (Integer) params.get("max");
        params.put("offset", offset.intValue());
    }

    if (!params.containsKey("offset")) {
        params.put("offset", 0);
    }
    Criteria criteria = currentSession().createCriteria(Producto.class);
    Criteria countCriteria = currentSession().createCriteria(Producto.class);

    if (params.containsKey("almacen")) {
        criteria.createCriteria("almacen").add(Restrictions.idEq(params.get("almacen")));
        countCriteria.createCriteria("almacen").add(Restrictions.idEq(params.get("almacen")));
    }

    if (params.containsKey("inactivo")) {
        criteria.add(Restrictions.eq("inactivo", true));
        countCriteria.add(Restrictions.eq("inactivo", true));
    } else {
        Disjunction propiedades = Restrictions.disjunction();
        propiedades.add(Restrictions.eq("inactivo", Boolean.FALSE));
        propiedades.add(Restrictions.isNull("inactivo"));
        criteria.add(propiedades);
        countCriteria.add(propiedades);
    }

    if (params.containsKey("filtro")) {
        String filtro = (String) params.get("filtro");
        Disjunction propiedades = Restrictions.disjunction();
        propiedades.add(Restrictions.ilike("sku", filtro, MatchMode.ANYWHERE));
        propiedades.add(Restrictions.ilike("nombre", filtro, MatchMode.ANYWHERE));
        propiedades.add(Restrictions.ilike("descripcion", filtro, MatchMode.ANYWHERE));
        propiedades.add(Restrictions.ilike("marca", filtro, MatchMode.ANYWHERE));
        propiedades.add(Restrictions.ilike("modelo", filtro, MatchMode.ANYWHERE));
        propiedades.add(Restrictions.ilike("ubicacion", filtro, MatchMode.ANYWHERE));
        criteria.add(propiedades);
        countCriteria.add(propiedades);
    }

    if (params.containsKey("order")) {
        String campo = (String) params.get("order");
        if (params.get("sort").equals("desc")) {
            criteria.addOrder(Order.desc(campo));
        } else {
            criteria.addOrder(Order.asc(campo));
        }
    }

    if (!params.containsKey("reporte")) {
        criteria.setFirstResult((Integer) params.get("offset"));
        criteria.setMaxResults((Integer) params.get("max"));
    }
    params.put("productos", criteria.list());

    countCriteria.setProjection(Projections.rowCount());
    params.put("cantidad", (Long) countCriteria.list().get(0));

    return params;
}

From source file:mx.edu.um.mateo.inventario.dao.impl.ProductoDaoHibernate.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override// ww w  .  j  ava 2 s.  co m
@Transactional(readOnly = true)
public List<Producto> listaParaSalida(String filtro, Long almacenId) {
    Criteria criteria = currentSession().createCriteria(Producto.class);
    criteria.createCriteria("almacen").add(Restrictions.idEq(almacenId));
    filtro = "%" + filtro + "%";
    Disjunction propiedades = Restrictions.disjunction();
    propiedades.add(Restrictions.ilike("sku", filtro, MatchMode.ANYWHERE));
    propiedades.add(Restrictions.ilike("nombre", filtro, MatchMode.ANYWHERE));
    propiedades.add(Restrictions.ilike("descripcion", filtro, MatchMode.ANYWHERE));
    propiedades.add(Restrictions.ilike("marca", filtro, MatchMode.ANYWHERE));
    propiedades.add(Restrictions.ilike("modelo", filtro, MatchMode.ANYWHERE));
    propiedades.add(Restrictions.ilike("ubicacion", filtro, MatchMode.ANYWHERE));
    criteria.add(propiedades);

    propiedades = Restrictions.disjunction();
    propiedades.add(Restrictions.eq("inactivo", Boolean.FALSE));
    propiedades.add(Restrictions.isNull("inactivo"));
    criteria.add(propiedades);

    criteria.add(Restrictions.gt("existencia", BigDecimal.ZERO));
    criteria.setMaxResults(10);
    return criteria.list();
}

From source file:net.firejack.platform.core.store.AbstractStore.java

License:Apache License

protected Criterion getRestrictions(SearchQuery query, Class<?> type) {
    Criterion criterion;/*from  w w w.j  a v  a 2  s. c  o m*/
    Object value = query.getValue();
    QueryOperation operation = query.getOperation();
    if (value != null
            && !(QueryOperation.FIELDEQUALS.equals(operation) || QueryOperation.FIELDNOTEQUALS.equals(operation)
                    || QueryOperation.FIELDGREATERTHAN.equals(operation)
                    || QueryOperation.FIELDLESSTHAN.equals(operation))) {
        if (value instanceof Collection) {
            Collection values = (Collection) value;
            if (Integer.class.equals(type)) {
                List<Integer> list = new ArrayList<Integer>();
                for (Object item : values) {
                    list.add(Integer.parseInt(item.toString()));
                }
                value = list;
            } else if (Long.class.equals(type)) {
                List<Long> list = new ArrayList<Long>();
                for (Object item : values) {
                    list.add(Long.parseLong(item.toString()));
                }
                value = list;
            } else if (java.sql.Date.class.equals(type) || Date.class.equals(type)) {
                List<Date> list = new ArrayList<Date>();
                for (Object item : values) {
                    Tuple<Date, QueryOperation> tuple = convertToDate(item, operation);
                    operation = tuple.getValue();
                    list.add(tuple.getKey());
                }
                value = list;
            } else if (Enum.class.isAssignableFrom(type)) {
                List<Enum> enumValues = new ArrayList<Enum>(values.size());
                for (Object item : values) {
                    Enum enumItem = prepareEnumFromSearchCriteria((Class<? extends Enum>) type, item);
                    enumValues.add(enumItem);
                }
                value = enumValues;
            }
        } else {
            if (Integer.class.equals(type)) {
                value = Integer.parseInt(value.toString());
            } else if (Long.class.equals(type)) {
                value = Long.parseLong(value.toString());
            } else if (Double.class.equals(type)) {
                value = Double.parseDouble(value.toString());
            } else if (java.sql.Date.class.equals(type) || Date.class.equals(type)) {
                Tuple<Date, QueryOperation> tuple = convertToDate(value, operation);
                value = tuple.getKey();
                operation = tuple.getValue();
            } else if (Enum.class.isAssignableFrom(type)) {
                value = prepareEnumFromSearchCriteria((Class<? extends Enum>) type, value);
            }
        }
    }

    if (!String.class.equals(type)
            && (QueryOperation.LIKECS.equals(operation) || QueryOperation.LIKECSFIRST.equals(operation)
                    || QueryOperation.LIKE.equals(operation) || QueryOperation.LIKEFIRST.equals(operation))) {
        operation = QueryOperation.EQUALS;
    }

    switch (operation) {
    case LIKECS:
        criterion = Restrictions.like(query.getField(), "%" + value + "%");
        break;
    case LIKECSFIRST:
        criterion = Restrictions.like(query.getField(), value + "%");
        break;
    case LIKE:
        criterion = Restrictions.ilike(query.getField(), "%" + value + "%");
        break;
    case LIKEFIRST:
        criterion = Restrictions.ilike(query.getField(), value + "%");
        break;
    case EQUALS:
        criterion = Restrictions.eq(query.getField(), value);
        break;
    case LESSTHAN:
        criterion = Restrictions.lt(query.getField(), value);
        break;
    case GREATERTHAN:
        criterion = Restrictions.gt(query.getField(), value);
        break;
    case ISNULL:
        criterion = Restrictions.isNull(query.getField());
        break;
    case ISNOTNULL:
        criterion = Restrictions.isNotNull(query.getField());
        break;
    case ISEMPTY:
        criterion = Restrictions.isEmpty(query.getField());
        break;
    case ISNOTEMPTY:
        criterion = Restrictions.isNotEmpty(query.getField());
        break;
    case NOTEQUALS:
        criterion = Restrictions.ne(query.getField(), value);
        break;
    case IN:
        criterion = generateInRestriction(query.getField(), (Collection) value);
        break;
    case NOTIN:
        criterion = Restrictions.not(generateInRestriction(query.getField(), (Collection) value));
        break;
    case FIELDEQUALS:
        criterion = Restrictions.eqProperty(query.getField(), value != null ? value.toString() : "");
        break;
    case FIELDNOTEQUALS:
        criterion = Restrictions.neProperty(query.getField(), value != null ? value.toString() : "");
        break;
    case FIELDGREATERTHAN:
        criterion = Restrictions.gtProperty(query.getField(), value != null ? value.toString() : "");
        break;
    case FIELDLESSTHAN:
        criterion = Restrictions.ltProperty(query.getField(), value != null ? value.toString() : "");
        break;
    default:
        throw new RuntimeException("Operation " + query.getField() + " is not a valid operation");
    }
    return criterion;
}

From source file:net.firejack.platform.core.store.BaseStore.java

License:Apache License

private Criteria createCriteria(Session session, Integer offset, Integer limit, Object example,
        List<String> nullableAssociations) {
    try {//from w  ww.j  a va  2s . com
        Class<?> exampleClass = example.getClass();

        Criteria criteria = session.createCriteria(exampleClass);
        //         Map<String, Criteria> subcriterias = new HashMap<String, Criteria>();

        if (limit != null && limit > -1) {
            criteria.setMaxResults(limit);
        }
        if (offset != null && offset > -1) {
            criteria.setFirstResult(offset);
        }

        Example exampleQuery = createExample(example);
        criteria.add(exampleQuery);

        SessionFactory sessionFactory = getHibernateTemplate().getSessionFactory();
        ClassMetadata meta = sessionFactory.getClassMetadata(exampleClass);
        String[] names = meta.getPropertyNames();
        Type[] propertyTypes = meta.getPropertyTypes();
        for (int i = 0; i < propertyTypes.length; i++) {
            if (propertyTypes[i].isAssociationType() && !propertyTypes[i].isCollectionType()) {
                String name = names[i];
                Object value = PropertyUtils.getProperty(example, name);
                if (value != null) {
                    Example subExample = createExample(value);
                    Criteria subcriteria = criteria.createCriteria(name);
                    //                  subcriterias.put(name, subcriteria);
                    subcriteria.add(subExample);
                } else if (nullableAssociations.contains(name)) {
                    criteria.add(Restrictions.isNull(name));
                }
            } else if (propertyTypes[i].isCollectionType()) {
                String name = names[i];
                Collection values = (Collection) PropertyUtils.getProperty(example, name);
                JoinTable joinTable = getMethodAnnotation(JoinTable.class, example, name);
                if (values != null && values.size() > 0 && joinTable != null) {
                    Table table = getClassAnnotation(Table.class, example);
                    Enumerated enumerated = getMethodAnnotation(Enumerated.class, example, name);
                    Object obj = values.iterator().next();
                    if (obj.getClass().isEnum()) {
                        String sqlWhere = "{alias}.id IN (SELECT DISTINCT id_" + table.name() + " FROM "
                                + joinTable.name() + " WHERE element IN (";
                        List<String> ordinals = new ArrayList<String>();
                        for (Object v : values) {
                            if (enumerated != null && EnumType.STRING.equals(enumerated.value())) {
                                ordinals.add("'" + String.valueOf(((Enum) v).name()) + "'");
                            } else {
                                ordinals.add(String.valueOf(((Enum) v).ordinal()));
                            }
                        }
                        String whereValues = StringUtils.join(ordinals.toArray(), ",");
                        sqlWhere = sqlWhere + whereValues + "))";
                        criteria.add(Restrictions.sqlRestriction(sqlWhere));
                    }
                }
            }
        }
        return criteria;
    } catch (IllegalAccessException e) {
        throw new RuntimeException(e);
    } catch (InvocationTargetException e) {
        throw new RuntimeException(e);
    } catch (NoSuchMethodException e) {
        throw new RuntimeException(e);
    }
}

From source file:net.firejack.platform.core.store.process.ProcessFieldStore.java

License:Apache License

/**
 * @see net.firejack.platform.core.store.process.IProcessFieldStore#findByProcessIdPlusGlobal(java.lang.Long)
 * @param processId - ID of the process for which the fields are being retrieved
 * @return//from ww  w .j  av  a 2 s  . c  o  m
 */
@Override
@Transactional(readOnly = true)
public List<ProcessFieldModel> findByProcessIdPlusGlobal(Long processId) {

    Map<String, String> aliases = new HashMap<String, String>();
    aliases.put("process", "p");

    List<Criterion> criterions = new ArrayList<Criterion>();
    Criterion globalFieldCriterion = Restrictions.isNull("p.id");
    if (processId != null) {
        Criterion processFieldCriterion = Restrictions.eq("p.id", processId);
        criterions.add(Restrictions.or(globalFieldCriterion, processFieldCriterion));
    } else {
        criterions.add(globalFieldCriterion);
    }

    Order order = createOrder("orderPosition", SortOrder.ASC);

    List<String> fetchPaths = Arrays.asList("registryNodeType");

    return findAllWithFilter(null, null, criterions, aliases, null, null, null, fetchPaths, order);
}

From source file:net.firejack.platform.core.store.registry.RegistryNodeStore.java

License:Apache License

@Override
@SuppressWarnings("unchecked")
@Transactional(readOnly = true)//from w  ww  .  j  a  v  a 2 s . com
public List<R> findChildrenByParentId(final Long registryNodeId, final SpecifiedIdsFilter<Long> filter) {
    return getHibernateTemplate().executeFind(new HibernateCallback() {
        public Object doInHibernate(Session session) throws HibernateException, SQLException {
            Criteria criteria = createCriteriaForFilter(session, filter);
            if (registryNodeId == null) {
                criteria.add(Restrictions.isNull("parent"));
            } else {
                criteria.add(Restrictions.eq("parent.id", registryNodeId));
            }
            return (List<RegistryNodeModel>) criteria.list();
        }
    });
}

From source file:net.firejack.platform.core.store.registry.RegistryNodeStore.java

License:Apache License

@Override
@SuppressWarnings("unchecked")
@Transactional(readOnly = true)//from   ww  w. j  av a 2 s  . c  om
public List<R> findChildrenByParentIdAndTypes(final Long registryNodeId, final List<String> discriminatorValues,
        final SpecifiedIdsFilter<Long> filter) {
    return getHibernateTemplate().executeFind(new HibernateCallback() {
        public Object doInHibernate(Session session) throws HibernateException, SQLException {
            Criteria criteria = createCriteriaForFilter(session, filter);
            if (registryNodeId == null) {
                criteria.add(Restrictions.isNull("parent"));
            } else {
                criteria.add(Restrictions.eq("parent.id", registryNodeId));
            }
            criteria.add(Restrictions.in("class", discriminatorValues));
            criteria.createAlias("main", "main", CriteriaSpecification.LEFT_JOIN);
            criteria.addOrder(Order.asc("sortPosition"));
            criteria.addOrder(Order.asc("name"));
            return (List<R>) criteria.list();
        }
    });
}