java - hibernate5.06,两实体关系为双向多对一,一端对象取特定的多端对象,hql如何写?

 这是个新名字 发布于 2022-10-28 15:28
People 表
---------------
id |   
---------------
 1 |
--------------

Book 表
-----------------------------
id |   type   |  _people_id (Fk)
-----------------------------
 1 |    1     |      1
-----------------------------
 2 |    1     |      1
-----------------------------
 3 |    2     |      1
-----------------------------
 4 |    3     |      1
-----------------------------


// People.hbm.xml>
// 
//   
//   
// 
public class People{
   private int id;
   private Set bookSet;
   public People(){}
   public People(int id,Set bookSet)
   {
      this.id=id;
      this.bookSet=bookSet;
    }
   //getter & setter
}

//Book.hbm.xml > 
//
public class Book{
   private int id;
   private int type;
   private People people;

   public Book(){}   
   //getter & setter
}

// dao层的方法 根据id获取用户及其 book.type=1的书
public People getPeopleById(int userId,int bookId)
{
   String hql="???????";
   
   return *省略*.uniqueResult();
}

取id=1的用户a,a包含type=1的两本书,hql语句怎么写?谢谢!

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有