I'm writing a service with JPA and Postgres db. I have a class named Student:
public class Student {
@id
private String id;
private String firstName;
private String lastName;
@OneToMany(cascade = CascadeType.ALL)
@JoinTable(name = "student_phone", joinColumns = @JoinColumn(name = "student_id"), inverseJoinColumns = @JoinColumn(name = "phone_id"))
private Set<Phone>;
// Setter and Getter
}
And a Phone class:
public class Phone {
@id
private String id;
private String number;
// Setter and Getter
}
Now there will be three tables in my db, following are columns in them:
- student: id, first_name, last_name
- phone: id, number
- student_phone: student_id, phone_id
Now every time I query a student from the db, the result contains the corresponding phones. Can I just get the content in student table? Some times I don't want to extend the phone information of a student.