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

Duplicates items after filtering #142

Closed
sebasira opened this issue Jan 8, 2022 · 2 comments
Closed

Duplicates items after filtering #142

sebasira opened this issue Jan 8, 2022 · 2 comments

Comments

@sebasira
Copy link

sebasira commented Jan 8, 2022

I having and issue with an Entity that has a @ManyToMany association. It's a Store and a StoreCategory many stores can be associated to many categories.

I have an Specification to search (like) the associated categories. And after:

dataTablesOutput = dataTableRepository.findAll(input, allColumnsSpecs);

I have this:
Screen Shot 2022-01-08 at 11 49 42

As you can see i have 2 recordsTotal and 3 recordsFiltered so after filtering I have more records than the total. And as you can see, items 0 and 1 are the same Entity.

What I'm doing to solve this is remove duplicates like this:

List<Integer> listWithDuplicates = Lists.newArrayList(5, 0, 3, 1, 2, 3, 0, 0);
List<Integer> listWithoutDuplicates = new ArrayList<>(
      new LinkedHashSet<>(listWithDuplicates));

Is this a bug or am I doing something wrong?

@darrachequesne
Copy link
Owner

Hi! Could you please provide a basic example reproducing the issue? You can fork the project here: https://github.com/darrachequesne/spring-data-jpa-datatables-sample/

A few things that I can think of:

  • are you fetching the StoreCategory eagerly with @ManyToMany(fetch = FetchType.EAGER)?
  • did you check the SQL logs with spring.jpa.properties.hibernate.show_sql=true?

Related: #87

@darrachequesne
Copy link
Owner

Closed due to inactivity, please reopen if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants