Hibernate 的HQL中一个经典函数elements的运用
Hibernate 的HQL中一个经典函数elements的使用
在传递索引和元素给集合时(elements and indices函数)和传递子查询的结果集时,SQL函数any, some, all, exists, in都是被支持的:
可编写如下Hql 语句完成查询:
- from Blog, Book
- where Blog.author in elements(Book.authors)
- and Book.id=?
对应的Sql近似如下:
- select blog.*
- from blog, book
- where (blog.author in ( select author.authorid
- from book_author
- where book.id=book_author.bookid))
- and book.id=?
项目中统计中使用如下:
摘取其中一部分:
if (condition.getHasGym() != null && condition.getHasGym()) {
sb.append(" and " + AmuseFacilities.FITNESSROOM.getCode() + " in elements(h.hotelInfo.hotelFacilityInfo.amuseFacilities)");
}
1 楼
smzd
2010-01-12
不错,学习了
2 楼
java.wj
2010-01-13
不错 长见识了