hibernate程序运行现多出一个记录

智慧健康 2015-08-29 05:55:29
person2 和 emails 一对多。
List list = session.createQuery(
" select p from Person2 p left join fetch p.emails e "
+ " where e.email like '%@yahoo.com.cn' ").list();
**//对应的sql语句执 行正常 ,调试看到 list取出来多出一条记录,看打印记录**

// 输出用户及其所有的用户
for (Person2 p : (List<Person2>) list) {
System.out.println("Person: " + p.getName()+ "-----"+ p.getId());
for (Email e : p.getEmails()) {
System.out.println("\tEmail: " + e.getEmail()); ** //打印记录如下**
}
}
打印结果: 最后一条19的记录怎么多出一个Email: 163@163.com。
Person: Jane-----8
Email: yahoo@yahoo.com.cn
Person: Jane-----9
Email: yahoo@yahoo.com.cn
Person: Jane-----10
Email: yahoo@yahoo.com.cn
Person: Jane-----15
Email: yahoo@yahoo.com.cn
Person: Jane-----16
Email: yahoo@yahoo.com.cn
Person: Jane-----19
Email: yahoo@yahoo.com.cn
Email: 163@163.com
...全文
121 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
a_b_a_b_a_b_a_b 2015-08-31
  • 打赏
  • 举报
回复
你用的左链接怎么没有条件啊,left join .... on ....
qq_21873571 2015-08-30
  • 打赏
  • 举报
回复
传说中的n+1

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧