when using the mapping relationship, we can associate the two tables by setting the association relationship between the master table or the slave table. When querying or doing other operations, we only need to query the master table to attach the slave table information, which is very convenient and concise. But the corresponding problem is that when I only need to query one of the tables separately, it will query the information of the associated table. Once there is a large amount of associated data, and I do not need the data from the table at this time, the efficiency will be greatly reduced. I would like to ask you gods what good way to associate the query when I need to associate, and not to associate the query when I do not need to associate? Ask for guidance?
public class Class{
@Id
private String id;
@Size(max = 20)
@Column(unique = true)
private String code;
@Size(max = 200)
private String name;
...
}
public class Student{
@Id
private String id;
@Size(max = 20)
private String code;
@Size(max = 200)
private String name;
@ManyToOne
private Class class;
...
}
Baidu said for a moment that adding the annotation @ JsonBackReference, to the setClass of the Student table can prevent the infinite loop containing the other party when the data is converted into json.
@JsonBackReference
public void setClass(Class class) {
this.class= class;
}