0
StuPersonal table-sno,stu_name,gender,FRID;
StuDegree table-sno,degree,dtype,regno,col_name,stP(FRID).
以上是我的表格定義(OnetoOne)的關係。 我的POJO類是如何使用條件從多個表中獲取記錄?
@Entity
public class StuPersonal {
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="ID")
private int sno;
@Column(name="NAME")
private String stu_name;
private int name_verify=0;
@Column(name="GENDER")
private String gender;
@OneToOne(cascade={CascadeType.ALL})
@JoinColumn(name="FRID")
private List<StuDegree> StuDegree;
@Id
private String FRID;
和
@Entity
public class StuDegree {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="sNO")
private int sno;
@Column(name="DEGREE")
private String degree;
@Column(name="DEGREE_TYPE")
private String dtype;
@Column(name="COLLEGE_NAME")
private String col_name;
@OneToOne
@JoinColumn(name="FRID")
private StuPersonal stP;
和我的主類是
Criteria criteria= s. createCriteria(StuDegree.class);
criteria.add(Restrictions.eq("col_name","PSYEC"));
List<StuDegree> colname =(List<StuDegree>) criteria.list();
我上面線擺脫Studegree表記錄中使用;
for (Iterator iterator = colname.iterator(); iterator.hasNext();)
{
StuDegree stdeg= (StuDegree) iterator.next();
{
Criteria criteria1= s.createCriteria(StuPersonal.class);
criteria.add(Restrictions.eq("stdeg.getFRID()","StuPersonal.getFRID()"));
List<StuPersonal> stuper=(List<StuPersonal>) criteria1.list();
System.out.println(stuper.size());
}
}
我用上面的代碼從Studegree表中使用FRID從StuPersonal表中取記錄,是不是?它不工作... PI建議...
你的代碼沒有意義。您不能在List類型的屬性上使用OneToOne。列表包含許多元素。所以這顯然是OneToMany。 –
謝謝JB Nizet .... –