-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: DISTINCT + GROUP BY + JPA 2 + Hibernate 3.6.7 Problem
PostPosted: Thu Sep 29, 2011 11:24 am 
Newbie

Joined: Tue Sep 13, 2011 2:16 pm
Posts: 5
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


Top
 Profile  
 
 Post subject: Re: DISTINCT + GROUP BY + JPA 2 + Hibernate 3.6.7 Problem
PostPosted: Thu Sep 29, 2011 2:14 pm 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
You should check the actual SQL that Hibernate generates in the two cases. In the problematic query my guess is that the problem is that you have two implicit joins to c.roda. The behavior of such queries was changed in Hibernate 3.5. To get the same behavior as before you need to use an explicit join (as you have already discovered). See http://opensource.atlassian.com/project ... e/HHH-4091 for some more information.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.