"org.hibernate.QueryException: could not resolve property" exception when using Envers with a class having @ManyToMany + @OrderBy annotated relation

Description

I get the following exception when trying to read a revision of my object, which has @ManyToMany relationship with a @OrderBy annotation on it:

java.lang.IllegalArgumentException: org.hibernate.QueryException: could not resolve property: mtid of: com.beepsoft.enversbug.Language_AUD [select new list(ee_, e) from publication_languages_AUD ee, com.beepsoft.enversbug.Language_AUD e_ where ee_.originalId.Publication_mtid = :Publication_mtid and e.originalId.REV.id = (select max(e2.originalId.REV.id) from com.beepsoft.enversbug.Language_AUD e2_ where e2_.originalId.REV.id <= :revision and e.originalId.mtid = e2.originalId.mtid) and ee.originalId.REV.id = (select max(ee2.originalId.REV.id) from publication_languages_AUD ee2_ where ee2_.originalId.REV.id <= :revision and ee.originalId.Publication_mtid = ee2.originalId.Publication_mtid and ee.originalId.languages_mtid = ee2.originalId.languages_mtid) and ee.REVTYPE != :delrevisiontype and e.REVTYPE != :delrevisiontype and (ee.originalId.languages_mtid = e.originalId.mtid or (ee.originalId.languages_mtid is null and e.originalId.mtid is null)) order by e_.mtid]

Here's a repo with a test case demonstrating the bug:

https://github.com/beepsoft/envers-bug

I use Spring Boot 2.4.4, but I think it is not Spring related.

If I use @OrderBy("languageCode") instead of the ID field @OrderBy("mtid") then it works all right. These very same annotations work all right in Hibernate 5.0.12.Final but now fail in Spring Boot 2.4.4 and Hibernate 5.4.29.Final

Environment

Spring Boot 2.4.4, Java 8

Activity

Show:
Balázs E. Pataki
April 24, 2021, 9:02 AM

Hi Chris,

could you take a look at this? Were you able to reproduce this bug?

Assignee

Chris Cranford

Reporter

Balázs E. Pataki