Home > Back-end >  JPA repository return one item from db but there are multiple item in the db
JPA repository return one item from db but there are multiple item in the db

Time:10-05

I have the following function in my repository

Set<Felhasznalo> findAllByNevContainsIgnoreCase(String nev);

When I use this function in the controller I got back one User.

For example, if I have a String "John" and I call the repo function with that string I got back "John Doe" but I also have "John Doe Jr" in the db and I need him too.

Why I get only one User?

CodePudding user response:

I see you are using a Set. Maybe you have implemented an equals() function which checks the names and the Set filters out duplicate elements.

Try changing your code to this:

List<Felhasznalo> findAllByNevContainsIgnoreCase(String nev);

So use a List.

CodePudding user response:

This is because you are storing your result in a Set which does not allow any duplicate values but here, you have duplicate names. Try changing Set to List as:

public List<Felhasznalo> findAllByNevContainsIgnoreCase(String nev);
  • Related