Bug 412191 - MongoDB ORDER BY not working with more than 1 field
Summary: MongoDB ORDER BY not working with more than 1 field
Status: NEW
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows 7
: P2 normal with 2 votes (vote)
Target Milestone: ---   Edit
Assignee: Nobody - feel free to take it CLA
QA Contact:
URL:
Whiteboard: mongodb
Keywords:
Depends on:
Blocks:
 
Reported: 2013-07-03 07:21 EDT by Bastian Spitzer CLA
Modified: 2022-06-09 10:24 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Bastian Spitzer CLA 2013-07-03 07:21:23 EDT
Query query = EntitiManager.createQuery("SELECT c FROM ContactHO WHERE c.companyId = :companyId ORDER BY c.firstNameNorm, c.lastNameNorm ASC");

The EclipseLink debug looks fine:

19:24:54.181 10:00:52,329 FINE [org.eclipse.persistence.session.vfs:/D:/server/jboss-as-7.1.1.Final/bin/content/module-1-SNAPSHOT.war/WEB-INF/classes/_mongo.sql] (http--127.0.0.1-8180-1) Executing MappedInteraction()
spec => null
properties => {mongo.collection=CONTACTHO, mongo.limit=10, mongo.operation=FIND}
input => [DatabaseRecord(
CONTACTHO.COMPANYID => 5893435701058912613
$sort => DatabaseRecord(
CONTACTHO.LASTNAME => 1
CONTACTHO.FIRSTNAME => 1))]

but the the resulting sort order is mixed up:

Thu Jun 27 19:24:54.186 [conn21] runQuery called siba.CONTACTHO { $query: { COMPANYID: 5894184253551005013 }, $orderby: { LASTNAMENORM: 1, FIRSTNAMENORM: 1 } }

DataBaseRecord preserves ordering by using Vector's for fields and values, which MongoRecord does not care for, its just a HashMap and fields get "ordered" by their hashCode.

MongoRecord hasnt changed in latest 2.5.1 or 2.6 releases/snapshots, so probably this problem still exists in these versions as well.
Comment 1 Bastian Spitzer CLA 2013-07-03 07:37:52 EDT
(In reply to comment #0)
> The EclipseLink debug looks fine:
> 
> 19:24:54.181 10:00:52,329 FINE
> [org.eclipse.persistence.session.vfs:/D:/server/jboss-as-7.1.1.Final/bin/
> content/module-1-SNAPSHOT.war/WEB-INF/classes/_mongo.sql]
> (http--127.0.0.1-8180-1) Executing MappedInteraction()
> spec => null
> properties => {mongo.collection=CONTACTHO, mongo.limit=10,
> mongo.operation=FIND}
> input => [DatabaseRecord(
> CONTACTHO.COMPANYID => 5893435701058912613
> $sort => DatabaseRecord(
> CONTACTHO.LASTNAME => 1
> CONTACTHO.FIRSTNAME => 1))]

this output is the wrong one, i did try to swap the sort parameters to see what happens. the coresponding one looks like this:

> 19:24:54.181 10:00:52,329 FINE
> [org.eclipse.persistence.session.vfs:/D:/server/jboss-as-7.1.1.Final/bin/
> content/module-1-SNAPSHOT.war/WEB-INF/classes/_mongo.sql]
> (http--127.0.0.1-8180-1) Executing MappedInteraction()
> spec => null
> properties => {mongo.collection=CONTACTHO, mongo.limit=10,
> mongo.operation=FIND}
> input => [DatabaseRecord(
> CONTACTHO.COMPANYID => 5893435701058912613
> $sort => DatabaseRecord(
> CONTACTHO.FIRSTNAME => 1
> CONTACTHO.LASTNAME => 1))]
Comment 2 Bastian Spitzer CLA 2013-07-03 07:58:30 EDT
this post contains the correct log entry's: http://www.eclipse.org/forums/index.php/m/1066316/#msg_1066316
Comment 3 Tom Ware CLA 2013-07-11 15:13:17 EDT
Setting target and priority.  See the following page for the meanings of these fields:

http://wiki.eclipse.org/EclipseLink/Development/Bugs/Guidelines

Community: Please vote for this bug if it is important to you.  Votes are one of the main criteria we use to determine which bugs to fix next.
Comment 4 Eclipse Webmaster CLA 2022-06-09 10:24:43 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink