我在模型中使用了@JoinTable并创建了表格,我保存了数据。
现在我想从那个子表中获取数据..如何通过JPA查询获取它..
我的代码是,
@Entity
public class Student {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer id;
@LazyCollection(LazyCollectionOption.FALSE)
@OneToOne(optional = false)
private User user;
@Column
private Integer handicap;
@OneToOne(targetEntity=StudentPro.class, cascade=CascadeType.ALL,
mappedBy="student", fetch = FetchType.LAZY, orphanRemoval = true)
@LazyCollection(LazyCollectionOption.FALSE)
private StudentPro studentPro;
@LazyCollection(LazyCollectionOption.FALSE)
@ManyToMany(cascade = CascadeType.ALL)
@JoinTable(
name = "student_favourite_pro",
joinColumns = {@JoinColumn(name = "student_id")},
inverseJoinColumns = {@JoinColumn(name = "pro_id")}
)
private List<Pro> favouritePros = new ArrayList<Pro>();
public StudentPro getStudentPro() {
return this.studentPro;}
public void setStudentPro(StudentPro studentPro) {
this.studentPro = studentPro;}
public Integer getId() {
return id;}
public void setId(Integer id) {
this.id = id;}
public User getUser() {
return user;}
public void setUser(User user) {
this.user = user;}
public Integer getHandicap() {
return handicap;}
public void setHandicap(Integer handicap) {
this.handicap = handicap;}
@Override
public String toString() {
return ToStringBuilder.reflectionToString(this);}
public void addFavouritePro(Pro pro) {
favouritePros.add(pro);}
public List<Pro> getFavouritePros() {
return favouritePros;}}
我想从student_favourite_pro表中获取数据。我该怎么做?
提前致谢
Lakshmi Priya.K