The collection-valued path xxx cannot be resolved to a valid association field

Hello,

I new to the forum and to Hibernate and have been tasked with migrating from openjpa to Hibernate. Most everything has gone well, but I am encountering a problem which does not seem to be solvable …

Here is the situation:
I have a Table “Department” which is modeled as an Entity. There is a second table “DepartmentRoles” which contains two columns - the departmentId as an FK to Department and a text field which contains the Role - this is NOT modeled as an Entity. Instead it is mapped as an ElementCollection in Department. Up to this point, all seems well. However, the is a defined NamedQuery which attempts to query based on the role - this looks like

@NamedQuery(name = "ac.Department.role", query = "SELECT c.uniqueId, c.code,  FROM Department c WHERE c.active = true AND :role MEMBER OF c.roles ORDER BY c.code"),

This worked just fine in openjpa - but now the complier is complaining that

The collection-valued path 'c.roles' cannot be resolved to a valid association field.

Roles is mapped as

    @ElementCollection(fetch = FetchType.LAZY, targetClass = DepartmentRole.class)
    @CollectionTable(schema = "bds", name = "DepartmentRole", joinColumns = @JoinColumn(name = "departmentId"))
    @Enumerated(EnumType.STRING)
    @Column(name = "role")
    private Set<DepartmentRole> roles = new HashSet<>();

I tried switching to a JOIN a la “LEFT JOIN c.roles r” (tip from Hibernate Tips: How to use @ElementCollection entries in a query

and using an IN elements() - the first gave the same error, elements apparently is not valid.

So - the question is - how do I get this to work. As I said earlier, this worked fine under openjpa - so I’m hoping it is a “small” matter.