Using the JPA Repository example

Asked

Viewed 30 times

0

I need to do a search in the bank where I have an object that is filled with everything except the id and check if it has any object that gives a "Match" with it and return it! I thought to make a @Query and check if all are equal, only my boss said that this is not the default and has a JPA Repository Example that I only found it this way here:

public interface LeagueRepository extends JpaRepository<League, Long>{

League findByName(String name);

boolean existsByTeams(Team team); }

Where you pass an object that is within your entity and it checks whether it has in tau column this object. But he doesn’t check the entity he’s in.

For example something like: "Obs this code below does not work"

public interface LeagueRepository extends JpaRepository<League, Long>{

League findByName(String name);

boolean exists(League league); }

Where the Legue object has everything but id.

1 answer

1


I don’t know any function that does it in jpa, but if you do it this way here:

Collection<League> findByNameAndOtherField (String name, String otherField);

I believe you find all the lines before performing your operation.

Note: sometimes the name of the method becomes giant and it pays to actually use the @query

  • The solution caters thank you very much.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.