data.dao.ColorGroupDao.java Source code

Java tutorial

Introduction

Here is the source code for data.dao.ColorGroupDao.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package data.dao;

import data.entity.ColorGroup;
import data.dao.parent.Dao;
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

/**
 *
 * @author bezdatiuzer
 */
@Repository("colorGroupDao")
public class ColorGroupDao extends Dao<ColorGroup> {

    @Override
    public Class getSupportedClass() {
        return ColorGroup.class;
    }

    public List<ColorGroup> findDict() {
        Criteria cr = currentSession().createCriteria(getSupportedClass());
        cr.setProjection(Projections.distinct(Projections.property("oldGroupId")));
        return cr.list();
    }

    public List<ColorGroup> findByQId(Long oldId) {
        Criteria cr = currentSession().createCriteria(getSupportedClass());
        cr.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
        cr.add(Restrictions.eq("oldId", oldId));
        return cr.list();
    }

}