在Hibernate中HQL语句的left join的例子详解基础上进行实现
1.修改com.jcuckoo.entity添加ShowBook类中的属性storageId、amount为Integer类型,并且修改对应的get/set方法
1.修改com.jcuckoo.entity添加ShowBook类中的属性storageId、amount为Integer类型,并且修改对应的get/set方法
2.在com.jcuckoo.dao中添加ShowBookDao类中添加方法findBySQL()
public List<ShowBook> findBySQL() {
String sql = "select b.id,b.name,b.author,b.publisher,b.price,b.pic,s.id as storageId,s.amount,s.inDate
from book b left join storage s on b.id=s.bookId";
SQLQuery query = this.getSession().createSQLQuery(sql);
query.addEntity(ShowBook.class);
return query.list();
}