Criteria Query and Bidirectional Polymorphic Association

I seem to have a problem doing a query with criteria using an entity that has a bidirectional association (OneToMany) with another polymorphic entity (Using join inheritance).
The problem only appears if the association is bidirectional (declared in both, the container using mappedBy from the other one), if i declare it only in the container and the other knows nothing about the query works perfectly.
Maybe there is something wrong in my query but im finding it really hard to locate my problem.

I have created a small example, using the hibernate-test-case from github, that reproduces my problem.

I uploaded it to my one drive cant attach tar.gz here:

This is the simple model in the example:

This is the criteria i build:

CriteriaBuilder builder = entityManager.getCriteriaBuilder();
        CriteriaQuery<GroupContainerVariantA> query
                = builder.createQuery(GroupContainerVariantA.class);
        Root<GroupContainerVariantA> root
                = query.from(GroupContainerVariantA.class);

        Join join = root.join("elementSet" ,JoinType.INNER);
        Path joinPath = builder.treat(join, ElementVariantA.class);

        Path field = joinPath.get("fieldVA1");
        Predicate predicate = builder.equal(field, "VA12");;

        List<GroupContainerVariantA> result
                = entityManager

        // See if it worked
                "More results than expected",1,result.size());
                "Not the correct element",eva2.getId(),result.get(0).getId());

If i use the bidirectional association i get this strange exception (if i use single side from the container the query works and return the correct element as the test verifies)

java.lang.ArrayIndexOutOfBoundsException: Index -1 out of bounds for length 3

	at org.hibernate.persister.entity.JoinedSubclassEntityPersister.getSubclassNameClosureBySubclassTable(

This is the data setup of the test:

        GroupContainerVariantA gca = new GroupContainerVariantA();
        ElementVariantA eva1 = new ElementVariantA();
        ElementVariantA eva2 = new ElementVariantA();
        ElementVariantB evb1 = new ElementVariantB();
        ElementVariantB evb2 = new ElementVariantB();

        gca.setElementSet(new HashSet<>(Arrays.asList(
                eva1, eva2, evb1, evb2)));


This might be a bug. Please create an issue for this and attach your reproducer: