mozun3 2017-08-03 14:21 采纳率: 0%
浏览 374
已结题

hibernate练习遇到有查询语句然而没有查询结果的问题

 //criteria查询测试
    @SuppressWarnings("unchecked")
    public List<House> criteriaQuery() {
        List<House> house =  HibernateSessionfactory.getSession()
                .createCriteria(House.class,"h")
//              .add(Restrictions.eq("h.price", 5000.00))
                .add(Restrictions.between("h.price", 4000.00, 7000.00))
//              .add(Restrictions.disjunction().add(Restrictions.eq("type_id", 1000)))
//              .add(Restrictions.like("title", "一",MatchMode.START))
//              .addOrder(Order.asc("houseid"))
                .list();

        return house;
    }

当我使用 .add(Restrictions.eq("h.price", 5000.00))完全没有问题。结果如下

 Hibernate: 
    select
        this_.houseid as houseid1_0_,
        this_.user_id as user2_1_0_,
        this_.type_id as type3_1_0_,
        this_.title as title1_0_,
        this_.description as descript5_1_0_,
        this_.price as price1_0_,
        this_.pubdate as pubdate1_0_,
        this_.floorage as floorage1_0_,
        this_.contact as contact1_0_,
        this_.street_id as street10_1_0_ 
    from
        `house` this_ 
    where
        this_.price=?
11001   中关村两居
11004   一室两厅
11005   一室两厅

是有结果的。问题是我注释掉eq语句改用between的时候就没有结果了。debug时house返回值也是null。执行结果是

 Hibernate: 
    select
        this_.houseid as houseid1_0_,
        this_.user_id as user2_1_0_,
        this_.type_id as type3_1_0_,
        this_.title as title1_0_,
        this_.description as descript5_1_0_,
        this_.price as price1_0_,
        this_.pubdate as pubdate1_0_,
        this_.floorage as floorage1_0_,
        this_.contact as contact1_0_,
        this_.street_id as street10_1_0_ 
    from
        `house` this_ 
    where
        this_.price between ? and ?

这就查询没有结果了。这个语句拿到MySQL里面去又是可以查到结果的,所以本身不是结果null,hibernate为什么没结果?我不太懂,郁闷啊,大神指教一下!

  • 写回答

0条回答

    报告相同问题?

    悬赏问题

    • ¥15 素材场景中光线烘焙后灯光失效
    • ¥15 请教一下各位,为什么我这个没有实现模拟点击
    • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 保护模式-系统加载-段寄存器