Why hql select from JavaBean but the table name?

时间:2017-04-10 01:48:24

标签: hql

I have a doubt, that is why in hql use from the JavaBean but the table name?

You can find the hql in below code.

My code is below:

@Repository(IElecSystemDDLDao.SERVICE_NAME)
public class ElecSystemDDLDaoImpl extends CommonDaoImpl<ElecSystemDDL> implements IElecSystemDDLDao {

public List<ElecSystemDDL> findSystemDDLListByDistinct() {

    List<ElecSystemDDL> systemList = new ArrayList<ElecSystemDDL>();

    String hql = "SELECT DISTINCT o.keyword FROM ElecSystemDDL o";  // Java Bean is ElecSystemDDL, table_name is Elec_SystemDDL
    List<Object> list = this.getHibernateTemplate().find(hql);

    if (list!=null && list.size()>0) {
        for (Object o: list) {
            ElecSystemDDL elecSystemDDL = new ElecSystemDDL();
            elecSystemDDL.setKeyword(o.toString());
            systemList.add(elecSystemDDL);
        }
    }
    return systemList;
}

}

0 个答案:

没有答案