Spring data Exists By Name and Different value for other field

Viewed 264

There is a way in Spring Data to find if exists a Name that not contains a Code?

Something like:

existsNameWithDifferentCode(String name, Long code);

I'm doing a update and I have to check if this update doesn't contain the same Name as another.

If I cannot do this with the Spring Data signature method, there is a way to do that with ExampleMatcher?

Or any suggestion?

2 Answers

You could use this method name

existsByNameAndCodeNot(String name, Long code);

I recommend to write a JPQL request.

This approach will allow you to more accurately obtain the necessary data from the database without:

thatLongNameForShortRequestWithMultipleConditions()
Related