Cześć - mam relację many to many między Userem a Eventem. Póki co wszystko działało ok do momentu kiedy stwierdziłem, że potrzebuję dodatkową kolumnę w tabeli wiążącej ( informacja o reakcji użytkownika na wydarzenie). Zrobiłem, więc tak:
@Entity
public class User {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
@OneToMany(mappedBy="user")
private Set<EventUser> eventUsers = new HashSet<>();
//
}
@Entity
public class Event {
@Id
@GeneratedValue(strategy= GenerationType.AUTO)
private long id;
@OneToMany(mappedBy="event")
private Set<EventUser> eventUsers = new HashSet<>();
//
}
@Entity
@Table(name = "Event_User")
public class EventUser {
@Id
@GeneratedValue(strategy= GenerationType.AUTO)
private long id;
private String reaction;
@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "user_id")
private User user;
@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "event_id")
private Event event;
//
}
I tak .. Spring tworzy tą dodatkową tabelę w bazie, wszystko niby ok, ale teraz nie wiem jak np wyszukać wszystkie wydarzenia po mailu usera ...
Wcześniej w interfejscie rozszerzającym JpaRepository<Event,Long> miałem metodę:
Collection<Event> findByUsersEmail(String email);
A teraz tak nie zrobię. Próbowałem utworzyć taką metodę:
Collection<Event> findByEventUsersUserEmail(String email);
ale wywala mi nieskończoną rekurencję ...
Rady ?