mozun3
2017-08-03 14:21hibernate练习遇到有查询语句然而没有查询结果的问题
1 //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条回答
为你推荐
- Hibernate Criteria 多表查询实体中有另一个实体 查询结果映射异常?
- java
- hibernate
- 1个回答
- Hibernate查询有关 in 的查询问题
- hibernate
- 0个回答
- spring的hibernate查询日期的语句
- hibernate
- 0个回答
- hibernate如何从数据库查询到map集合
- 数据库
- hibernate
- 1个回答
- hibernate多表关联查询
- hibernate
- 3表
- 3个回答
换一换