Can't ORDER BY on @Formula with DISTINCT on SQLServer

Description

Here is my Entities :

Here is my JPA Query :

And here is the generated SQL :

And here is the error I get from SQLServer :

I think Hibernate should use the formula alias instead of repeating the formula. I've tested directly in SQLServer and that query is working :

Moreover, that error appears only if I use DISTINCT on the first SELECT (and I must have that DISTINCT in my business use case).

Environment

JBoss 7.1.1.Final (hibernate module updated to 4.1.8.Final) using org.hibernate.dialect.SQLServer2008Dialect on SQLServer 2008R2

Status

Assignee

Unassigned

Reporter

Anthony Ogier

Fix versions

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure