关于Hibernate子类没有自动查询的问题
本帖最后由 dut_singer 于 2013-12-12 14:30:48 编辑 用Struts2+Hibernate做web应用,两个实体类Error和User,N->1映射
主要代码如下:Error.hbm.xml
<class name="Error" table="error_table">
<id name="error_id" column="error_id">
<generator class="identity"/>
</id>
<property name="report_time" type="java.util.Date"/>
<property name="report_user" type="java.lang.String"/>
<property name="report_dep" type="java.lang.String"/>
<property name="error_show_des" type="java.lang.String"/>
<property name="level" type="java.lang.Integer"/>
<property name="report_status" type="java.lang.Integer"/>
<!-- 到User表的外键,N->1 -->
<many-to-one name="user" class="User">
<column name="userid"></column>
</many-to-one>
<many-to-one name="platform" class="Platform">
<column name="platform_id"></column>
</many-to-one>
</class>
<class name="User" table="user_table">
<id name="userid">
<generator class="identity"/>
</id>
<property name="username"/>
<property name="password"/>
<property name="name"/>
<property name="birthday"/>
<property name="email"/>
<property name="cellphone"/>
<!-- dep_id 是 user中的属性,columnid应该是外键 -->
<many-to-one name="dep" cascade="all" class="Department" column="dep_id" />
</class>
this.setError((Error)sess.get(Error.class,error.getError_id()));
<td>记录人</td><td><label><s:property value="%{error.user.username}"/></label> </td></tr>
System.out.println(error.getUser().getUsername());