2013年12月12日星期四

With regard to the sub- class does not automatically Hibernate query

 This post last edited by dut_singer on 2013-12-12 14:30:48
do with Struts2 + Hibernate web application , two entity classes Error and User, N-> 1 mapping
The main code is as follows : 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>

User.hbm.xml

<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>

display the results action

this.setError((Error)sess.get(Error.class,error.getError_id()));

display the query results jsp

<td>记录人</td><td><label><s:property value="%{error.user.username}"/></label> </td></tr>

just write the main code , do not know can not understand that ,
jsp now take fewer than username, but if the action , adding

System.out.println(error.getUser().getUsername());

jsp able to get to the username , which is why ? Query defined in the parent class subclass also need to show it, in order to obtain sub- categories of data it?
------ Solution ---------------------------------------- ----
I feel like with lazy loading about when you may get to the error, his user has not actually loaded , when the jsp page , read the error of the session has been closed , not attending user the
------ For reference only ------------------------------------ ---
  The reply was deleted administrator at 2013-12-12 14:36:10

------ For reference only ---------------------------------- -----

it was so , hbm.xml increase lazy = "false" solved the problem , thank you !
------ For reference only -------------------------------------- -
minute of it . . . . .

没有评论:

发表评论