0

This is a rather simple jpa query but the ordering is never working. doesn´t matter if i add ASC or DESC

SELECT hfp FROM Lap l INNER JOIN l.footprints hfp WHERE l.id = :id ORDER BY hfp.date ASC

After this query my output is always the same.

Query query = em.createNamedQuery("findHardwareFootprintsWithLapIdOrderByDateASC");
        query.setParameter("id", lapId);
        List<HardwareFootprint> results = query.getResultList();
        System.out.println(results);

Output:

[Footprint[ id=21 type=NormalHandshake date=05/10/2014 08:13:41.808], Footprint[ id=20 type=NormalHandshake date=05/10/2014 08:13:21.123], Footprint[ id=18 type=NormalHandshake date=05/10/2014 08:13:11.512]]

SQL Log:

SELECT t0.ID, t0.DATE, t0.TYPE FROM HARDWAREFOOTPRINT t0, LAP_HARDWAREFOOTPRINT t2, LAP t1 WHERE ((t1.ID = ?) AND ((t2.Lap_ID = t1.ID) AND (t0.ID = t2.footprints_ID))) ORDER BY t0.DATE ASC

Anybody an idea?

perotom
  • 851
  • 13
  • 33
  • You'll have to elaborate: how do you determine that it doesn't work? Where is the code executing this query and testing it? Which JPA engine are you using? What is the generated SQL query? I doubt such a huge bug would have been unnticed until now, so the bug is probably in your code. – JB Nizet Oct 24 '14 at 15:21
  • i am using hibernate. i added further code. The problem is the output is always the same. doesn´t matter if i change it to asc or desc. – perotom Oct 24 '14 at 15:39
  • Then your entities probably all have the same date. Or you're not executing the query you think you're executing. If you told us what the generated SQL is, we could at least check that. – JB Nizet Oct 24 '14 at 15:42
  • i added the output. the entities aren´t the same. i am 100% sure that the right sql is executed. how do i show you the sql? – perotom Oct 24 '14 at 15:55
  • You need to enable SQL logging in your config. Google it. – Dojo Oct 24 '14 at 15:59
  • By pasting it in your question. If you mean that you don't know how to enable SQL logging, then how can you be 100% sure that the right SQL is executed? Anyway, go to http://docs.jboss.org/hibernate/core/4.3/manual/en-US/html_single/, hit Ctrl-F, and search for show_sql. – JB Nizet Oct 24 '14 at 16:03
  • Because i changed only this query to something different (output somethink other) and it showed me something different. Thank you very much i will enable it. – perotom Oct 24 '14 at 16:07
  • Ok i logged the sql and the query gets definitely called. Any other ideas? – perotom Oct 24 '14 at 16:15
  • Then the bug is probably in the code of the entity. – JB Nizet Oct 24 '14 at 16:27
  • And where do you think? – perotom Oct 24 '14 at 16:31
  • maybe there is a prolbem with derby? – perotom Oct 24 '14 at 16:41
  • Derby is used and tested by thousands of projects. Hibernate as well. You're probably the only one that uses your code. There is a much higher probability that the bug is in your code. How could I say where, since you didn't post it? I can't see your screen. – JB Nizet Oct 24 '14 at 19:47
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/63608/discussion-between-user2630406-and-jb-nizet). – perotom Oct 24 '14 at 19:56
  • The data in the output is actually sorted DESCENDING BY DATE so at least the ordering seems to work somehow? – unwichtich Oct 26 '14 at 19:16
  • i think thats the order how i inserted the data – perotom Oct 27 '14 at 14:23

0 Answers0