Say I have two entities:
class User {
@Id private int id;
private String name;
private int addressId;
}
class Address {
@Id private int id;
private String street;
}
Is it possible to do this:
interface UserRepository extends CrudRepository<User, Integer> {
@Query(nativeQuery=true,
value=
"select * from user "
+ "inner join address a on a.id = u.addressId "
+ "where a.street = :address.street")
List<User> findByAddress(@Param("address") Address address);
}
That is: accept an entity (Address in this case) as the parameter, but reference one of its properties (Address.street in this case) in the native query?
For various reasons, I cannot use "normal" @ManyToMany and JPA queries for these two entities.