As a follow-up, this goes slightly deeper than a ClassCastException. The basic problem is that @OrderBy is something that Envers does not yet fully support. In order to support this feature, I'm going to need to reworking how RelationQueryGenerator instances work. Envers builds a series of RelationQueryGenerator instances based on the types of relational mappings it finds when parsing the ORM metadata. For index-based collections that use @IndexColumn or @OrderColumn, the order of the collection was handled when we inserted the element into the collection by providing the exact index offset in the collection itself. This meant that basically no special query fragment was needed to properly order the query result. Unfortunately, that same idea won't work for @OrderBy because the semantics that surround this annotation differs. The place where we need to address support for @OrderBy]} would be inside the {{RelationQueryGenerator instances. But the underlying issue is that we build the queries these generators use up-front before a SessionFactory exists, and so we aren't able to make use of the template-parsing used by ORM nor can we access anything from a persister perspective because those do not yet exist. I'm going to see about delaying the creation of the queries until they're needed at run-time. This allows the parts of ORM to exist when we need them. If that works, we can re-optimize it by adding a SessionFactoryObserver that still builds the queries as a part of application start-up rather than run-time but remains delayed until the SessionFactory exists. |