日期:2014-05-20  浏览次数:20692 次

hibernate——多对一,取多方的值怎么来?
subjectinfo 与 stutemp 两个表,stutemp 的外键是subjectinfo 的sub_id

<class catalog="subjectinfo" lazy="true" name="hibernate.model.Stutemp" table="stutemp">
  <id name="tempId" type="java.lang.Integer">
  <column name="temp_id"/>
  <generator class="identity"/>
  </id>
<many-to-one class="hibernate.model.Subjectinfo" fetch="select" name="subjectinfo">
  <column name="sub_id"/>
  </many-to-one>


<hibernate-mapping>
<class catalog="subjectinfo" lazy="true" name="hibernate.model.Subjectinfo" table="subjectinfo">
  <id name="subId" type="java.lang.Integer">
  <column name="sub_id"/>
  <generator class="identity"/>
  </id>

  <set inverse="true" name="stutemps" sort="unsorted">
  <key>
  <column name="sub_id"/>
  </key>
  <one-to-many class="hibernate.model.Stutemp"/>
  </set>Stutemp

public class Stutemp implements java.io.Serializable {

// Fields

private Integer tempId;
private Teachers teachers;

private Subjectinfo subjectinfos;
// Constructors

public class Subjectinfo implements java.io.Serializable {

// Fields

private Integer subId;
private Teachers teachers;

private Set stutemps = new HashSet(0);
// Constructors

public Set getStutemps() {
return stutemps;
}

public void setStutemps(Set stutemps) {
this.stutemps = stutemps;
}

查询了subjectinfo表后,怎样通过所得结果确定Stutemp中是否存在subjectinfo的值? <s:if test=subjectinfo.stutemp!=null>请问绿色部分怎么写?这样是不对了,不知道还要做什么判断?大家能否帮个忙?谢谢!

------解决方案--------------------