Working with Spring Data JPA repositories and with the methods annotated with @Query
like the below one, I dont know if this query should be in the UserRepository
or AddressRepository
in this case. Its even more complicated when you want to return attributes from both entities. Thanks!
public interface UserRepository extends JpaRepository<User, Long> {
@Query("select u.name from User u JOIN u.address a where u.emailAddress = :emailAddress and a.zipcode=:zipcode")
User findByEmailAddressAndZipCode(String emailAddress, String zipcode);
}