New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Predicate With Multiple Conditions On The Same Field Fails #442

Closed
joefitzgerald opened this Issue Jun 14, 2013 · 3 comments

Comments

Projects
None yet
2 participants
@joefitzgerald

I'm seeing some strange behavior when trying to AND multiple fields with the same name - the last one in wins, and it's because of the use of a LinkedHashMap in MongodbSerializer.

My expectation: startsWithIgnoreCase(somefield, startValue) && endsWithIgnoreCase(somefield, endValue) should result in a mongo query that includes both restrictions.

The reality: startsWithIgnoreCase(somefield, startValue) && endsWithIgnoreCase(somefield, endValue) results in a mongo query with only the last restriction on somefield.

Is my expectation incorrect? Is there another way to achieve this query? Or is this a defect?

Reproduction

Suppose you have a predicate whose String representation is:

Asset.active = true && 
endsWithIgnoreCase(Asset.fields.os,2003) &&
startsWithIgnoreCase(Asset.fields.os,Windows)

...and you create a MongodbQuery and invoke MongodbQuery.where(predicate). Then you invoke list() on the query.

MongodbQuery.list() calls MongodbQuery.createCursor() which in turn leverages MongodbSerializer.handle(predicate) - source.

The String representation of the where value in QueryMetadata is:

Asset.active = true && 
endsWithIgnoreCase(Asset.fields.os,2003) &&
startsWithIgnoreCase(Asset.fields.os,Windows)

As the expression is processed by handle, visit(Operation<?> expr, Void context) (source) is hit. Visit leverages BasicDBObject (extends BasicBSONObject, extends LinkedHashMap <String, Object>) for the AND scenario. As the expression is processed, the conditions are put in this structure: here. Because this is not a multi-value HashMap, if multiple conditions exist for the same key, then only the last one will end up in the resulting BasicDBObject.

Consequently, information is lost in the serialization of the expression to the MongoDB query.

timowest added a commit that referenced this issue Jun 15, 2013

timowest added a commit that referenced this issue Jun 15, 2013

@joefitzgerald

This comment has been minimized.

Show comment
Hide comment
@joefitzgerald

joefitzgerald Jun 19, 2013

I've run my tests against the 3.2.1 SNAPSHOT build (https://oss.sonatype.org/content/repositories/snapshots/com/mysema/querydsl/querydsl-mongodb/3.2.1.BUILD-SNAPSHOT/) and your commits have addressed the issue I reported.

Any ETA on a release that would include this? Thanks for your help!!

I've run my tests against the 3.2.1 SNAPSHOT build (https://oss.sonatype.org/content/repositories/snapshots/com/mysema/querydsl/querydsl-mongodb/3.2.1.BUILD-SNAPSHOT/) and your commits have addressed the issue I reported.

Any ETA on a release that would include this? Thanks for your help!!

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Jun 19, 2013

Member

I will make a release next week.

Member

timowest commented Jun 19, 2013

I will make a release next week.

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Jun 26, 2013

Member

Released in 3.2.1

Member

timowest commented Jun 26, 2013

Released in 3.2.1

@timowest timowest closed this Jun 26, 2013

@timowest timowest added this to the 3.2.1 milestone Apr 14, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment