Querydsl case when not working as expected with element collection

Solution for Querydsl case when not working as expected with element collection
is Given Below:

I have this entity

@Entity
@Table(name = "DOCUMENT")
public class Document {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "ID", nullable = false)
    private Long id;

    @Column(name = "NAME", nullable = false)
    private String name;

    @Column(name = "BROKER_ID", nullable = true)
    private String brokerId;

    @ManyToOne
    @JoinColumn(name = "TYPE_ID", nullable = false)
    private DocumentType type;

    @Column(name = "UPLOAD_DATE", nullable = false)
    private Date uploadDate;

    @Column(name = "LANGUAGE", nullable = false)
    @Enumerated(EnumType.STRING)
    private Language language;

    @ElementCollection
    @CollectionTable(name = "DOCUMENT_VIEWED_BY", joinColumns = @JoinColumn(name = "DOCUMENT_ID", referencedColumnName = "ID"))
    @Column(name = "VIEWED_BY", nullable = false)
    private Set<String> viewedBy;

    @Column(name = "DOCUMENT_REFERENCE", nullable = false)
    private String documentReference;

//constructors getters setters

Then I’m trying to get all the documents from the database by brokerId, type and pagination. Everything is working fine, the only issue is that I want to fetch an extra column with a case expression like this

final BooleanExpression b = new CaseBuilder()
      .when(document.viewedBy.contains(brokerId)).then(true).otherwise(false);

final JPAQuery<DocumentProjection> query = new JPAQuery<>(this.em);
      query.select(Projections.constructor(DocumentProjection.class, 
      document.brokerId,
      document.documentReference, 
      document.name, 
      document.uploadDate, 
      document.type.id, 
      document.language
      ,b));

Getting this query

Hibernate: 
    select
        document0_.BROKER_ID as col_0_0_,
        document0_.DOCUMENT_REFERENCE as col_1_0_,
        document0_.NAME as col_2_0_,
        document0_.UPLOAD_DATE as col_3_0_,
        document0_.TYPE_ID as col_4_0_,
        document0_.LANGUAGE as col_5_0_,
        case 
            when ? in (viewedby1_.VIEWED_BY) then ? 
            else 0 
        end as col_6_0_ 
    from
        DOCUMENT document0_ cross 
    join
        DOCUMENT_VIEWED_BY viewedby1_ 
    where
        document0_.ID=viewedby1_.DOCUMENT_ID 
        and (
            document0_.BROKER_ID=? 
            or document0_.BROKER_ID is null
        ) 
        and (
            document0_.TYPE_ID in (
                ? , ? , ?
            )
        ) 
    order by
        document0_.UPLOAD_DATE desc limit ?

Which is fine, the only issue is in the case clause… I want something like when viewedby1_.VIEWED_BY = ? then instead of when ? in (viewedby1_.VIEWED_BY) then so I tried to change the line from document.viewedBy.contains(brokerId) to document.viewedBy.any().eq(brokerId) because this is how I do it in whereclauses in other parts of my code and it gives me that syntax that I want, but when it comes to case in select it gives me an error

Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: document.viewedBy is not mapped
    at org.hibernate.hql.internal.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:169) ~[hibernate-core-5.4.30.Final.jar:5.4.30.Final]
    at org.hibernate.hql.internal.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:91) ~[hibernate-core-5.4.30.Final.jar:5.4.30.Final]
    at org.hibernate.hql.internal.ast.tree.FromClause.addFromElement(FromClause.java:77) ~[hibernate-core-5.4.30.Final.jar:5.4.30.Final]
    at org.hibernate.hql.internal.ast.HqlSqlWalker.createFromElement(HqlSqlWalker.java:333) ~[hibernate-core-5.4.30.Final.jar:5.4.30.Final]
    at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:3765) ~[hibernate-core-5.4.30.Final.jar:5.4.30.Final]
    at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:3654) ~[hibernate-core-5.4.30.Final.jar:5.4.30.Final]
    at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:737) ~[hibernate-core-5.4.30.Final.jar:5.4.30.Final]
    at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:593) ~[hibernate-core-5.4.30.Final.jar:5.4.30.Final]
    at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:330) ~[hibernate-core-5.4.30.Final.jar:5.4.30.Final]
    at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:278) ~[hibernate-core-5.4.30.Final.jar:5.4.30.Final]
    at org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:276) ~[hibernate-core-5.4.30.Final.jar:5.4.30.Final]
    at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:192) ~[hibernate-core-5.4.30.Final.jar:5.4.30.Final]

Thank you.