2

When I create a method of a Spring Data repository like findByName(…) everything works fine. But when using findByField1AndName(…) Spring Data MongoDB generates query only for the last parameter:

{ name : 'qwerty' }

But I expected it generates

{ field1 : 'something', name : 'querty' }

What's the problem? Please help.

UPD1: If anyone has such a problem, you can use @Query annotation to manually build your query, example below:

@Query("{ region: ?0, product: ?1, direction: ?2, deliveryCondition: ?3, sortament: ?4}")
QuotationKey findByRegionAndProductAndMarketDirectionAndDeliveryConditionAndSortament(
        Geography region, Product product, MarketDirection direction,
        DeliveryCondition deliveryCondition, Sortament sortament);

2 Answers 2

1

Not sure if am missing something. I tried 1.0.3 and 1.0.4 and it still doesn't work. The only working version right now looks like 1.0.1

When i tried for something like findByZipCodeAndName with 1.0.3 and 1.0.4, this is what i see in logs

MongoQueryCreator [DEBUG] Created query Query: { "zipCode" : "test"}, Fields: null, Sort: null

With 1.0.1 it works as expected:

MongoQueryCreator [DEBUG] Created query { "zipCode" : "test" , "name" : "blah"}

Apparently in the new releases only the first field is interpreted and queried for.

0
0

It seems you stumbled over a bug present in 1.0.2 and 1.1.M1. The fixes have been out for a while so upgrading to a recent version (1.0.4, 1.1 RC1) should do the trick.

2
  • I used spring-data-mongodb 1.0.3.RELEASE, it seems that bug still there.
    – Andrey
    Sep 21, 2012 at 11:43
  • If you think so, please file a bug with a test case included :). Sep 23, 2012 at 15:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.