hibernate关联数据作为查询条件

hibernate中,在前台当表关联的数据作为查询条件时,因为hibernate只接受能识别的属性(即在对应的hbm.xml文件中能找到的属性),如果没有,则在后台实现类中的hql中需要用别名进行查询:

前台页面:

后台的查询hql:

if(gqm.getGtm() != null &&
                gqm.getGtm().getSm() != null &&
                gqm.getGtm().getSm().getUuid() != null &&
                gqm.getGtm().getSm().getUuid() != -1){
            dc.createAlias("gtm", "g");
            dc.createAlias("g.sm", "s");
            dc.add(Restrictions.eq("s.uuid", gqm.getGtm().getSm().getUuid()));
        }

 

 别名的另外一种写法:

   am        a
        a.bm   ab
        ab.cm  abc
        abc.dm abcd
        abcd.name

posted on 2017-03-23 11:41  小左1990  阅读(117)  评论(0编辑  收藏  举报

导航