Skip to content
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

Repository keyword query findByInId with pageable not returning correctly [DATAMONGO-1126] #2042

Closed
spring-projects-issues opened this issue Dec 21, 2014 · 3 comments
Assignees
Labels
in: repository Repositories abstraction type: bug A general bug

Comments

@spring-projects-issues
Copy link

chris opened DATAMONGO-1126 and commented

I've been trying to use the In-keyword with identifiers and making the query pageable. The query returns results but getTotalElements(…) and getTotalPages(…) always returns 0. Also when you try to get any other page than 0, no results return. I've tried using In with another member other than id and it works as expected. Below is a strip down example I used for testing;

I've created 3 types and 10 items per those types, results in a total of 30 items.

@Document
public class Item {

    @Id
    private String id;
    private String type;
}
public interface ItemRepository extends MongoRepository<Item, String> {

    Page<Item> findByIdIn(Collection ids, Pageable pageable);
    Page<Item> findByTypeIn(Collection types, Pageable pageable);
}
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {MongoDbConfig.class})
@TransactionConfiguration(defaultRollback = false)
public class TestPageableIdIn {

    @Autowired
    private ItemRepository itemRepository;
    
    private List<String> allIds = new LinkedList<>();

    @Before
    public void setUp() {
        itemRepository.deleteAll();
        String[] types = {"SWORD", "SHIELD", "ARMOUR"};

        // 10 items per type
        for (String type : types) {
            for (int i = 0; i < 10; i++) {
                String id = UUID.randomUUID().toString();
                allIds.add(id);
                itemRepository.save(new Item(id, type));
            }
        }
    }

    @Test
    public void testPageableIdIn() {
        
        Pageable pageable = new PageRequest(0, 5);
        
        // expect 5 Items returned, total of 10 Items(SWORDS) in 2 Pages
        Page<Item> results = itemRepository.findByTypeIn(Arrays.asList("SWORD"), pageable);
        Assert.assertEquals(5, results.getContent().size());
        Assert.assertEquals(10, results.getTotalElements());
        Assert.assertEquals(2, results.getTotalPages());
        
        // expect 5 Items returned, total of 30 Items in 6 Pages
        results = itemRepository.findByIdIn(allIds, pageable);
        Assert.assertEquals(5, results.getContent().size());
        Assert.assertEquals(30, results.getTotalElements()); // this is returning 0
        Assert.assertEquals(6, results.getTotalPages());     // this is returning 0
    }
}

Affects: 1.6.1 (Evans SR1)

Issue Links:

  • DATAMONGO-1120 Pageable queries timeout or return incorrect counts
    ("duplicates")

Backported to: 1.6.2 (Evans SR2)

@spring-projects-issues
Copy link
Author

Christoph Strobl commented

Thanks chris for reporting. Yes there is an issue in 1.6.1.RELEASE that seems to be already fixed in the upcoming 1.6.2 and 1.7.0 releases. Would you mind checking if it works for you with 1.6.2.SNAPSHOT?

@spring-projects-issues
Copy link
Author

Oliver Drotbohm commented

This very much looks like a duplicate of DATAMONGO-1120. Resolving as such

@spring-projects-issues
Copy link
Author

chris commented

thanks, sorry I've been offline for awhile. I can still check when I get back

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: repository Repositories abstraction type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants