日期:2014-05-19  浏览次数:20638 次

Hibernate中使用DetachedCriteria进行多字段条件查询(之间关系为or)的问题
如主旨,DetachedCriteria查询条件对象Restrictions.or(lhs,rhs);只能假如两个参数,但是我的查询条件有14个,而且之间都是or的关系,那么该如何写呢? 
我自己尝试用嵌套来写,可是tomcat报错,具体代码如下: 
Java code

//创建查询对象detachedCriteria
        DetachedCriteria detachedCriteria = DetachedCriteria.forClass(CmNetPlan.class);
        
        detachedCriteria.add(Restrictions.or(Restrictions.or(Restrictions.or(Restrictions.or(Restrictions.or(Restrictions.or(
                Restrictions.eq("monAm", monAm), 
                Restrictions.eq("monPm", monPm)), 
                Restrictions.or(
                        Restrictions.eq("tuesAm", tuesAm), 
                        Restrictions.eq("tuesPm", tuesPm))),
                        Restrictions.or(Restrictions.or(
                                Restrictions.eq("wedAm", wedAm), 
                                Restrictions.eq("wedPm", wedPm)), 
                                Restrictions.or(
                                        Restrictions.eq("thursAm", thursAm), 
                                        Restrictions.eq("thursPm", thursPm)))),
                                        Restrictions.or(Restrictions.or(
                                                Restrictions.eq("friAm", friAm),
                                                Restrictions.eq("friPm", friPm)),
                                                Restrictions.or(
                                                        Restrictions.eq("satAm", satAm), 
                                                        Restrictions.eq("satPm", satPm)))),
                                                        Restrictions.or(
                                                                Restrictions.eq("sunAm", sunAm), 
                                                                Restrictions.eq("sunPm", sunPm))), null));


请各位同仁指点一下啊。。。

------解决方案--------------------
你的错误呢?
------解决方案--------------------
楼主把错误贴出来吧!~!