1

I have an entity Subjects:

public class Subject {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    private String name;

    @OneToOne
    private Teacher teacher;
    @ManyToMany
    private Set<Teacher> replacingTeachers;

    @JsonIgnore
    @ManyToOne
    @JoinColumn(name = "class_id")
    private Class myClass;
}

And I want to make a query which searches by myClass_id and by either teacher_id or by replacingTeachers' ids (to contain an id). How to do this with Spring JPA? I tried this:

    Optional<Subject> findByTeacherIdAndMyClassIdOrReplacingTeachersContains(final Long teacherId, final Long classId);

0 Answers0