JPQL and Enums via @ElementCollection

Following a hibernate upgrade to 6 - I have tried 6.1.x, 6.2.x, 6.3.x I cannot fix the following relationship and associated queries that previously worked in 5.x

@CollectionTable(name = "user_role", joinColumns = {@JoinColumn(name="user_id")})
@ElementCollection(targetClass = Role.class)
@Enumerated
@Column(name = "role_id", nullable = false)
private Set<Role> roles = new HashSet<>();

Role is an enum and user_role is a two column join table [user_id, role_id]

In the query there where clause cannot be provided whereas is worked in hibernate 5.x


WHERE roles = org.package.Role.ROLE_ENUM

throws this
class org.hibernate.metamodel.mapping.internal.PluralAttributeMappingImpl cannot be cast to class org.hibernate.metamodel.mapping.BasicValuedMapping (org.hibernate.metamodel.mapping.internal.PluralAttributeMappingImpl and org.hibernate.metamodel.mapping.BasicValuedMapping are in unnamed module of loader ‘app’)

It is a collection so fair enough but any attempts to refine… for example

WHERE roles.name = org.package.Role.ROLE_ENUM cause the following…

Caused by: java.lang.IllegalStateException: Basic paths cannot be dereferenced

Please create an issue in the issue tracker(https://hibernate.atlassian.net) with a test case(https://github.com/hibernate/hibernate-test-case-templates/blob/master/orm/hibernate-orm-6/src/test/java/org/hibernate/bugs/JPAUnitTestCase.java) that reproduces the issue.

The proper way to do this though, is to join the roles and use the join alias in the where clause e.g. from MyEntity e join e.roles r where r = Role.ROLE_ENUM

Thanks for the response. Looks like it already covered here…

https://hibernate.atlassian.net/browse/HHH-16604