I have @Entity, which looks like this
@Entity
public class Plane {
@Id
private Long planeid;
@OneToMany(fetch = FetchType.LAZY, targetEntity = Passenger.class, cascade ={CascadeType.ALL}, mappedBy = "planeid")
private List<Passenger> passengers;
...
I am using such method in interface extending JPARepository:
@Transactional
public interface PlaneRepository extends JpaRepository<Plane, Long> {
@Query(value = "SELECT * FROM planes p JOIN passengers v USING(planeid) WHERE v.name = 'Carlos' GROUP BY p.planeid", nativeQuery = true)
List<Plane> findAllPlanesMatching();
}
As a result of this method I get list of all plane objects, which have passenger with name 'Carlos', but inside of every plane object List contains list of all passenger, but I would like this list have only passengers called 'Carlos'. Is there any way to do that?