Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Hibernate 7: a collection criterion next to an association block of the same collection throws ClassCastException

Đang mở
#16,633 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
groovy, java
Lĩnh vực
backend, databases

Hướng nghiên cứu

The failure is a ClassCastException where pets resolves to an SqmSetJoin instead of an SqmPluralValuedSimplePath, so start from how the Hibernate 7 criteria path resolves a property name that a join block has already created. Reproduce with the TCK Person and Pet domains, using the four cases in the issue (block first and criterion first, at top level and inside owner { }). Done means all four cases return the same results as Hibernate 6 and the regression tests pass.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Expected Behavior

A collection criterion such as isNotEmpty('pets') restricts the collection whether it comes before or after a pets { ... } block in the same criteria, at the top level or inside another association block.

Actual Behaviour

On Hibernate 7, unless the criterion comes before the block inside another association block, the query fails with:

java.lang.ClassCastException: class org.hibernate.query.sqm.tree.domain.SqmSetJoin cannot be cast to class org.hibernate.query.sqm.tree.domain.SqmPluralValuedSimplePath

The path pets resolves to the join the block made for the association instead of to the collection-valued path that isNotEmpty expects. At the top level this happens in either order, because the join type a block of the queried class records becomes an alias definition of the query.

Steps To Reproduce

With the TCK Person (hasMany = [pets: Pet]) and Pet (owner) domains on Hibernate 7:

// top level, block first: ClassCastException
Person.createCriteria().list {
    pets { eq('name', 'Rex') }
    isNotEmpty('pets')
}

// top level, criterion first: ClassCastException
Person.createCriteria().list {
    isNotEmpty('pets')
    pets { eq('name', 'Rex') }
}

// inside another block, block first: ClassCastException
Pet.createCriteria().list {
    owner {
        pets { eq('name', 'Rex') }
        isNotEmpty('pets')
    }
}

// inside another block, criterion first: works
Pet.createCriteria().list {
    owner {
        isNotEmpty('pets')
        pets { eq('name', 'Rex') }
    }
}

Found while reviewing https://github.com/apache/grails-core/pull/16559#discussion_r4256550230; the behaviour is the same with and without that PR.

Environment Information
  • Hibernate 7 (grails-data-hibernate7), Hibernate ORM 7.4.10
  • JDK 21
Example Application

No response

Version

8.0.x

Ngôn ngữ chính
Groovy
Star
2.9k
Fork
976
Merge trung bình
21 giờ 14 phút
Pull request đã merge (30 ngày)
174

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của apache/grails-core

Tất cả issue của apache/grails-core

Issue tương tự

Thêm issue về Backend & API Design

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.