Hibernate 集合链接

发布于 2024-08-27 17:38:52 字数 581 浏览 4 评论 0原文

我有两个实体,

University   
   courses

Course
   students

我想访问大学中的所有学生。我尝试了以下查询,

select u.courses.students from university u

但出现以下异常。

org.hibernate.QueryException: illegal attempt to dereference collection [university0_.id.courses] with element property reference [students] [ select u.courses.students from com.socialsite.persistence.University u  ]
    at org.hibernate.hql.ast.tree.DotNode$1.buildIllegalCollectionDereferenceException(DotNode.java:46)
  .....

谁能解释一下这有什么问题吗?

I have two Entities

University   
   courses

Course
   students

i want to access all the students in a university. I tried the following query

select u.courses.students from university u

i got the following exception.

org.hibernate.QueryException: illegal attempt to dereference collection [university0_.id.courses] with element property reference [students] [ select u.courses.students from com.socialsite.persistence.University u  ]
    at org.hibernate.hql.ast.tree.DotNode$1.buildIllegalCollectionDereferenceException(DotNode.java:46)
  .....

can anyone explain what is wrong with this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

箜明 2024-09-03 17:38:52

嗯,u.courses 是一个集合,没有 students 属性(这是单个Course 的属性)。

Well, u.courses is a Collection and doesn't have a students property (which is a property of a single Course).

流殇 2024-09-03 17:38:52

我想通了。谢谢帕斯卡

   select distinct s
   from University u
     inner join u.courses as c
       inner join c.students as s

i figured it out. Thanks pascal

   select distinct s
   from University u
     inner join u.courses as c
       inner join c.students as s
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文