Возможно ли это?
Я хотел бы получить все объекты AAA с определенным идентификатором CCC.incidentAssessmentResultId, используя JPARepository. Возможно ли это?
@Entity
@Table(schema = "aaa", name = "table")
public class AAA {
@Column(name = "kryterium")
private String criterion;
@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true)
@JoinColumn(name = "id_kryterium_naruszen")
private List<BBB> violationFactors;
}
public class BBB {
@Column(name = "czynnik")
private String factor;
@Column(name = "stopien")
private float degree;
@JsonManagedReference
@OneToOne(mappedBy = "violationFactor")
private CCC incidentAssessmentFactor;
}
public class CCC {
@Column(name="komentarz")
private String comment;
@Column(name="ocena_naruszenia_wynik_id", updatable=false, insertable=false)
private Long incidentAssessmentResultId; //-> I'd like to find AAA objects with a specific incidentAssessmentResultId ID
@Column(name="czynnik_wybrany")
private Boolean factorIsSelected;
@Column(name = "wartosc_wybrana")
private float value;
@Repository
public interface ViolationCriterionRepository extends JpaRepository<AAA, Long> {
// @Query("select vc from AAA vc left join vc.violationFactors vf left join vf.incidentAssessmentFactor iaf where iaf.incidentAssessmentResultId = ?1")
List<AAA> findByViolationFactors_IncidentAssessmentFactor_IncidentAssessmentResultId(Long incidentId);
}
Теперь, когда я вызываю ViolationCriterionRepository .findAll (), я получаю все данные, но хочу получить все данные, но с определенными объектами CCC. Я пытался с помощью метода ниже в моем репозитории, но я получаю 0 результатов.
UPDATE
Мой репо:
@Repository
public interface ViolationCriterionRepository extends JpaRepository<ViolationCriterion, Long> {
@Query("select vc from AAA vc join vc.violationFactors vf join vf.incidentAssessmentFactor iaf where iaf.incidentAssessmentResultId = ?1")
List<AAA> findByIncidentAssessmentResultId(Long incidentId);
}