我正在使用一个名为publicationrepository的jparepository,希望找到某个人的所有出版物。这些类通过类作者连接。
人员类别:
@Entity
public class Person {
@Id
private String email;
private String telefon;
private String password;
@OneToMany(mappedBy = "person")
Set<Author> Author;
}
作者类别:
@Entity
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Author {
@Id
private int id;
@ManyToOne
@JoinColumn(name="Person_ID")
Person person;
@ManyToOne
@JoinColumn(name="Publication_ID")
Publication publication;
private String Date;
private String Writerstatus;
}
出版物类
@Entity
@AllArgsConstructor
@NoArgsConstructor
@Data
public class Publication {
@Id
private int id;
private String publicationname;
@OneToMany(mappedBy = "publication")
Set<Author> author;
}
以及publicationrepository
public interface ProjektRepository extends JpaRepository<Projekt,Integer> {
}
1条答案
按热度按时间aiazj4mn1#
试试这个。
我还建议用实体的表名对实体进行注解:
@Table(name = "publication")
对于多对多关系,可以使用手动生成表Author
您还可以使用@ManyToMany
注解。好的教程:https://attacomsian.com/blog/spring-data-jpa-many-to-many-mapping