в моем текущем проекте я использую Hibernate с JPA.
У меня есть следующие объекты:
Объект A:
@Entity
@Table(name = "a")
public class A implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GenericGenerator(name = "uuid", strategy = "uuid2")
private String id;
@Column(name = "name")
private String name;
@OneToMany
private Set<Association> associations = new HashSet<>();
}
Объект B:
@Entity
@Table(name = "b")
public class B implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GenericGenerator(name = "uuid", strategy = "uuid2")
private String id;
@Column(name = "description")
private String description;
@OneToMany
private Set<Association> associations = new HashSet<>();
}
Ассоциация объектов:
@Entity
@Table(name = "association")
public class Association implements Serializable {
private static final long serialVersionUID = 1L;
@ManyToOne
@JoinColumn(name = "a_id", referencedColumnName = "id")
A a;
@ManyToOne
@JoinColumn(name = "b_id", referencedColumnName = "id")
B b;
...other columns..
}
Теперь я хотел бы реализовать слой хранилища для A следующим образом:
@Repository
public interface ARepository extends JpaRepository<A, Long> {
//Here I would like to write the function/query get all the As with many-to-many relationships.
}