Hibernate, dao 사용자 정의 sql 조회 결과 구현

public interface FactoryExtDao{
    List getBenchmarkingFactory(List factoryIds);
}
public class FactoryExtDaoImpl implements FactoryExtDao {
    @Autowired
    EntityManager entityManager;

    @Override
    public List getBenchmarkingFactory(List factoryIds) {
        String jql = "select f.id factoryId,f.name factoryName, fd.device_id factoryDeviceId, f.max_cod MaxCOD, " +
            "f.daily_handling_capacity dailyHandlingCapacity from factory f, factory_device fd where " +
            "f.id = fd.factory_id and f.id in :factoryIds";
        if (CollectionUtils.isEmpty(factoryIds)) {
            return Lists.newArrayList();
        }
        Query query = entityManager.createNativeQuery(jql);
        query.setParameter("factoryIds", factoryIds);
        query.unwrap(SQLQuery.class).addScalar("factoryId", StandardBasicTypes.LONG).addScalar("factoryName", 
        StandardBasicTypes.STRING).addScalar("factoryDeviceId", StandardBasicTypes.STRING).addScalar("MaxCOD", 
        StandardBasicTypes.FLOAT).addScalar("dailyHandlingCapacity", StandardBasicTypes.LONG).setResultTransformer(
        Transformers.aliasToBean(BenchmarkingFactoryDto.class));
	return query.getResultList();}

좋은 웹페이지 즐겨찾기