Described the problem here https://discourse.hibernate.org/t/new-query-building-in-hibernate-6/7283
I have attached test cases for hibernate 5 (work without error) and 6 (with error).