Hi,
I wanna register this strange issue in the case of someone having the same problem.
When I run the code below in Jboss 6.0.Final with the default hibernate:
Code:
EntityManager em = getEntityManager();
Query query = em.createQuery("SELECT DISTINCT(c.roda) FROM Carro c ORDER BY c.roda.numeroSequencia ");
List<Roda> results = (List<Roda>) query.getResultList()
I got the exception:
com.microsoft.sqlserver.jdbc.SQLServerException: ORDER BY items must appear in the select list if SELECT DISTINCT is specified.
But when I run the same code in Jboss 5.1.GA with the default hibernate the query works fine.
The solution I´ve found is:
Code:
EntityManager em = getEntityManager();
Query query = em.createQuery("SELECT DISTINCT(r) FROM Carro c INNER JOIN c.roda r ORDER BY r.numeroSequencia ");
List<Roda> results = (List<Roda>) query.getResultList()
I don´t know if it is a bug or not, but fortunately the work around is simple.
OBS: My database is SQLSERVER 2008
[]´s