JPA CriteriaBuilider custom JOIN ON clause

Is there a way to get resulting sql query like:

select xx from A a inner join B b on a.id=b.a_id OR a.id=b.some_another_id

I tried to customize “on” clause with criteria builider but this results in

select xx from A a inner join B b on a.id=b.a_id AND a.id=b.some_another_id

Yeah I know it is weird but…

Re-qualifying as a Hibernate ORM topic. Hibernate Search is a different project.

It cannot be done with Criteria API.

It can only be done with HQL since 5.1:

select a
from EntityA
inner join EntityB b 
     on a.id = b.id or a.id = b.someOtherProperty