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).
JBoss 7.1.1.Final (hibernate module updated to 4.1.8.Final) using org.hibernate.dialect.SQLServer2008Dialect on SQLServer 2008R2