@Entity
@Table(name="seance")
@Data
public class Seance {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(nullable = false, unique = true)
private Integer id;
private java.time.LocalTime displayTime;
@ManyToMany(mappedBy = "seances")
@JsonIgnore
private List<Repertoire> repertoires = new ArrayList<>();
@OneToMany(mappedBy = "reservationSeance", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@JsonIgnore
private List<Reservation> reservations = new ArrayList<>();
}
@Entity
@Table(name="reservation")
@Data
public class Reservation {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(nullable = false, unique = true)
private Integer id;
private java.time.LocalDate reservationDate;
@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JoinColumn(name = "id_seance")
private Seance reservationSeance;
.........
}
I have two entities in relation ManyToOne, and I try extends JpaRepository
public interface ReservationRepository extends JpaRepository<Reservation,Integer> {
List<Reservation> findReservationsByReservationSeance(Seance seance);
}
But as parametr i must use all Object Seance it is possible using JpaRepository find reservation only by id and displayTime from Seance Table or need to write own method?
You can add your own query in your ReservationRepository
@Query("SELECT r FROM Reservation r WHERE r.reservationSeance.id=:seanceId AND r.reservationSeance.displayTime = :displayTime")
public List<Reservation> findReservations(@Param("seanceId") int seanceId, @Param("displayTime") LocalTime displayTime);