Steve Ebersole commented on Improvement HHH-4394

I worked on this over the past 2 days and found a solution. It relies on the OrderByFragmentTranslator I added for JPA's @OrderBy handling. There is a little trickery that goes on with ordering by properties that contain formula mappings. All the test suite tests pass, including quite a few that leverage formulas. The fix works with both @javax.persistence.@OrderBy and @org.hibernate.annotations.OrderBy.

The solution involved a number of concepts. First was the exposure of new method named org.hibernate.persister.entity.Loadable#getTableAliasForColumn. Loadable is an "optional" interface for @EntityPersister implementors. See the javadocs for its details.

Also had to change a few things in the org.hibernate.sql.ordering.antlr package. org.hibernate.sql.ordering.antlr.ColumnMapper was changed to return a new interface org.hibernate.sql.ordering.antlr.SqlValueReference instead of just Strings; this was needed to handle columns and formulas individually. org.hibernate.sql.ordering.antlr.SqlValueReference has 2 sub-interfaces: {{org.hibernate.sql.ordering.antlr.ColumnReference and {{org.hibernate.sql.ordering.antlr.FormulaReference.

The org.hibernate.sql.ordering.antlr.OrderByFragmentTranslator interface itself was altered to return a new contract org.hibernate.sql.ordering.antlr.OrderByTranslation rather than just a String. OrderByTranslation represents the "tokenized" form of the ordering fragment. The old form used a pattern of {{$PlaceHolder.[column_name]}} as the tokens; I changed that to just use {[column_name}}. This made search/replace much easier. OrderByTranslation is used to finalize the translation process, via its #injectAliases method which accepts a org.hibernate.sql.ordering.antlr.OrderByAliasResolver parameter. In the main code base, org.hibernate.sql.ordering.antlr.OrderByAliasResolver is the bridge back to the CollectionPersister to determine the appropriate table alias to use to qualify columns.

This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators.
For more information on JIRA, see: http://www.atlassian.com/software/jira