读书人

hibernate多对一取多方的值如何

发布时间: 2011-11-30 21:16:57 作者: rapoo

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>请问绿色部分怎么写?这样是不对了,不知道还要做什么判断?大家能否帮个忙?谢谢!

[解决办法]

读书人网 >J2EE开发

热点推荐