Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Eclipselink and oderby does not work on criteria fetch query
Eclipselink and oderby does not work on criteria fetch query [message #1005079] Thu, 24 January 2013 12:58 Go to next message
Mindaugas Pocius is currently offline Mindaugas PociusFriend
Messages: 7
Registered: October 2012
Junior Member
How to add groupBy criteria to the code below? Because if I add criteriaQuery.groupBy(from.get(minutis.Preke_.prId)); - I get exactly the same SQL statement (like without groupBy):

CriteriaBuilder cb = MinutisManager.getInstance().getCriteriaBuilder();
CriteriaQuery criteriaQuery = cb.createQuery(minutis.Preke.class);
Root<minutis.Preke> from = criteriaQuery.from(minutis.Preke.class);
from.fetch(minutis.Preke_.tiekejai, JoinType.LEFT).fetch(minutis.PrekeTiekejas_.tiekejas, JoinType.LEFT);

TypedQuery<minutis.Preke> typedQuery = MinutisManager.getInstance().createQuery(criteriaQuery);

criteriaQuery.distinct(true) is not an option for me. Because that command hangs the whole statement and if I use EXPLAIN:
If I use GROUP BY on the query, then EXPLAIN is:

Images are attached

It give the following SQL statements both times (with and without criteriaQuery.groupBy(from.get(minutis.Preke_.prId));):
SELECT ... FROM preke t1 LEFT OUTER JOIN preke_tiekejas t0 ON (t0.pr_id = t1.pr_id) LEFT OUTER JOIN tiekejas t2 ON (t2.tiek_id = t0.tiek_id) LEFT OUTER JOIN gamintojas t3 ON (t3.gam_id = t1.gam_id) LEFT OUTER JOIN google_compare t4 ON (t4.pr_id = t1.pr_id) LEFT OUTER JOIN grupe t5 ON (t5.pgs_id = t1.pgs_id) LEFT OUTER JOIN preke_kaina t6 ON (t6.pr_id = t1.pr_id) ORDER BY t1.pr_id LIMIT ?, ?
  • Attachment: distinct.jpg
    (Size: 51.59KB, Downloaded 1205 times)
  • Attachment: groupby.jpg
    (Size: 48.31KB, Downloaded 136 times)

[Updated on: Thu, 24 January 2013 13:47]

Report message to a moderator

Re: Eclipselink and oderby does not work on criteria fetch query [message #1005106 is a reply to message #1005079] Thu, 24 January 2013 13:43 Go to previous message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1284
Registered: July 2009
Senior Member
This is also posted here

Please turn EclipseLink logging on and show the SQL that it generates, and what you are after. The best solution will probably be to just remove the fetch join.
Previous Topic:Eclipselink is reverting my LAZY settings
Next Topic:EL OSGi EntityManagerFactoryBuilder creates EntityManagerFactory for different DBs wrongly
Goto Forum:

Current Time: Wed Feb 21 09:59:40 GMT 2018

Powered by FUDForum. Page generated in 0.01670 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software