Announcement Announcement Module
Collapse
No announcement yet.
MongoDB: Issue with query creation with multiple criteria using Repository Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • MongoDB: Issue with query creation with multiple criteria using Repository

    Per instructions under section 4.3.2.2 of http://static.springsource.org/sprin...s.introduction, I'm creating a repository interface that has this method:

    public interface BaseFareRepository extends PagingAndSortingRepository<BaseFare, String> {
    ...
    List<BaseFare> findByDepartureOidAndOfficeOidAndCabinCategoryOidA ndAdultsQtyAndChildrenQty(Long departureOid, Long officeCode, Long cabinCategoryOID, Integer AdultsQty, Integer ChildrenQty);

    When I execute a query like the following:

    List<BaseFare> result = baseFareRepository.findByDepartureOidAndOfficeOidA ndCabinCategoryOidAndAdultsQtyAndChildrenQty(new Long(70000), new Long(3), new Long(1), new Integer(2), new Integer(2));
    ...}

    When executed the query criteria is resolved to the following:
    Query: { "childrenQty" : 2}, Fields: null, Sort: null, stripping all other criteria specified in the method.

    I think I've narrowed down the issue to the following method in org.springframework.data.repository.query.parser.A bstractQueryCreator:
    private S createCriteria(PartTree tree) {

    S base = null;
    Iterator<Object> iterator = parameters == null ? null : parameters.iterator();

    for (OrPart node : tree) {

    S criteria = null;

    for (Part part : node) {

    criteria = criteria == null ? create(part, iterator) : and(part, criteria, iterator);
    }

    base = base == null ? criteria : or(base, criteria);
    }

    return base;
    }

    where base only returns the last portion of the Criteria derived from the method name (basically by writing over rather than adding to the previous query criteria already processed).

    I'm using spring-data-mongodb 1.0.3.RELEASE.

    Any follow-up will be appreciated

    Sebastian

  • #2
    As a workaround I've used the MongoDB JSON based query methods and field restriction as follows:
    Code:
    public interface BaseFareRepository extends PagingAndSortingRepository<BaseFare, String> {
    ...
    	@Query( "{'departureOid': ?0, 'officeOid': ?1, 'cabinCategoryOid': ?2, 'adultsQty': ?3, 'childrenQty': ?4 }")
    	List<BaseFare> findByDepartureOfficeCabinAdultsAndChildren(Long departureOid, Long officeCode, Long cabinCategoryOID, Integer AdultsQty, Integer ChildrenQty);

    Comment

    Working...
    X