hibernate 高级查询 query 或查询 or ,Restrictions

今天用了写hibernate高级查询时用了Restrictions(当然 Expression也是可以以的)这个类.感觉不错.
下面的代码写的不易读.其实核心就是一句
Restrictions.or(Restrictions.like(),Restrictions.or(Restrictions.like,........))
里面的or可以无限加的.还是比较好用

Session session = getHibernateTemplate().getSessionFactory()
                .openSession();
        Criteria criteria = session.createCriteria(Film.class);
        List list = criteria.add(
            Restrictions.or(Restrictions.like("description", key,MatchMode.ANYWHERE),
              Restrictions.or(Restrictions.like("name", key,MatchMode.ANYWHERE),
                Restrictions.or(    Restrictions.like("direct", key,MatchMode.ANYWHERE),
                  Restrictions.or(Restrictions.like("mainplay",key,MatchMode.ANYWHERE),
                          Restrictions.like("filearea", key,MatchMode.ANYWHERE)))))).list();

        session.close();
        return list;

你可能感兴趣的:(hibernate,query,session,list)