liuhong2099 2009-06-20 22:08
浏览 267
已采纳

hibernate查询子表对象在页面上找不到!!!!

在main方法里 可以通过 主表 查询到 字表

但放到action里 页面上找不到子表的字段,控制台也打印出了信息

POJO类 get set方法省略
[code="java"]

主表的pijo
private Integer id;

private String password;

private String names;

private Set ta2s = new HashSet();

字表的pojo

private Integer id;

private String kecheng;

private Integer ids;

private Ta1 ta1;

[/code]

[size=x-small]Action里的方法[/size]
[code="java"]

public ActionForward lists(ActionMapping mapping,ActionForm form,
HttpServletRequest request,HttpServletResponse response) throws Exception{

Query query = getSession().createQuery("from Ta1 "); 
List list =  query.list(); 

request.setAttribute("views", list);

return mapping.findForward("lis");

}
[/code]

hbm配置文件
[code="java"]

   <set name="ta2s" cascade="all" lazy="false" inverse="true"> 
    <key column="ids"> </key> 
    <one-to-many class="org.test.dao.Ta2"/> 
    </set> 

    <many-to-one name="ta1"  insert="false" lazy="false" update="false" class="org.test.dao.Ta1"> 
    <column name="ids"> </column> 
    </many-to-one> 

[/code]

jsp页面
[code="java"]





${st.names}


${st.kecheng}


href=""> src="img_files/del.gif" border=0>



href=""> src="img_files/edit.gif" border=0>

                        </TR>
                        </c:forEach>
                        </c:when>
                        <c:otherwise>
                            <%response.sendRedirect(request.getContextPath()+"/view.do?method=lists"); %>
                        </c:otherwise>
                        </c:choose>

[/code]

异常信息

[code="java"]

javax.servlet.jsp.el.ELException: Unable to find a value for "kecheng" in object of class "org.test.dao.Ta1" using operator "."
org.apache.commons.el.Logger.logError(Logger.java:481)
org.apache.commons.el.Logger.logError(Logger.java:498)
org.apache.commons.el.Logger.logError(Logger.java:611)
org.apache.commons.el.ArraySuffix.evaluate(ArraySuffix.java:340)
org.apache.commons.el.ComplexValue.evaluate(ComplexValue.java:145)
org.apache.commons.el.ExpressionEvaluatorImpl.evaluate(ExpressionEvaluatorImpl.java:263)
org.apache.commons.el.ExpressionEvaluatorImpl.evaluate(ExpressionEvaluatorImpl.java:190)
org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:899)
org.apache.jsp.list_jsp._jspx_meth_c_forEach_0(list_jsp.java:228)
org.apache.jsp.list_jsp._jspx_meth_c_when_0(list_jsp.java:191)
org.apache.jsp.list_jsp._jspService(list_jsp.java:120)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1063)
org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:386)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:229)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

[/code]

控制台打印出来的信息

控制台打印出来的show_sql

select ta1x0_.id as id4_, ta1x0_.password as password4_, ta1x0_.names as names4_ from test_ssh.ta1 ta1x0_
Hibernate: select ta2s0_.ids as ids1_, ta2s0_.id as id1_, ta2s0_.id as id5_0_, ta2s0_.kecheng as kecheng5_0_, ta2s0_.ids as ids5_0_ from test_ssh.ta2 ta2s0_ where ta2s0_.ids=?
Hibernate: select ta2s0_.ids as ids1_, ta2s0_.id as id1_, ta2s0_.id as id5_0_, ta2s0_.kecheng as kecheng5_0_, ta2s0_.ids as ids5_0_ from test_ssh.ta2 ta2s0_ where ta2s0_.ids=?
Hibernate: select ta2s0_.ids as ids1_, ta2s0_.id as id1_, ta2s0_.id as id5_0_, ta2s0_.kecheng as kecheng5_0_, ta2s0_.ids as ids5_0_ from test_ssh.ta2 ta2s0_ where ta2s0_.ids=?
Hibernate: select ta2s0_.ids as ids1_, ta2s0_.id as id1_, ta2s0_.id as id5_0_, ta2s0_.kecheng as kecheng5_0_, ta2s0_.ids as ids5_0_ from test_ssh.ta2 ta2s0_ where ta2s0_.ids=?
Hibernate: select ta2s0_.ids as ids1_, ta2s0_.id as id1_, ta2s0_.id as id5_0_, ta2s0_.kecheng as kecheng5_0_, ta2s0_.ids as ids5_0_ from test_ssh.ta2 ta2s0_ where ta2s0_.ids=?
Hibernate: select ta2s0_.ids as ids1_, ta2s0_.id as id1_, ta2s0_.id as id5_0_, ta2s0_.kecheng as kecheng5_0_, ta2s0_.ids as ids5_0_ from test_ssh.ta2 ta2s0_ where ta2s0_.ids=?
Hibernate: select ta2s0_.ids as ids1_, ta2s0_.id as id1_, ta2s0_.id as id5_0_, ta2s0_.kecheng as kecheng5_0_, ta2s0_.ids as ids5_0_ from test_ssh.ta2 ta2s0_ where ta2s0_.ids=?
Hibernate: select ta2s0_.ids as ids1_, ta2s0_.id as id1_, ta2s0_.id as id5_0_, ta2s0_.kecheng as kecheng5_0_, ta2s0_.ids as ids5_0_ from test_ssh.ta2 ta2s0_ where ta2s0_.ids=?
Hibernate: select ta2s0_.ids as ids1_, ta2s0_.id as id1_, ta2s0_.id as id5_0_, ta2s0_.kecheng as kecheng5_0_, ta2s0_.ids as ids5_0_ from test_ssh.ta2 ta2s0_ where ta2s0_.ids=?
Hibernate: select ta2s0_.ids as ids1_, ta2s0_.id as id1_, ta2s0_.id as id5_0_, ta2s0_.kecheng as kecheng5_0_, ta2s0_.ids as ids5_0_ from test_ssh.ta2 ta2s0_ where ta2s0_.ids=?
Hibernate: select ta2s0_.ids as ids1_, ta2s0_.id as id1_, ta2s0_.id as id5_0_, ta2s0_.kecheng as kecheng5_0_, ta2s0_.ids as ids5_0_ from test_ssh.ta2 ta2s0_ where ta2s0_.ids=?
Hibernate: select ta2s0_.ids as ids1_, ta2s0_.id as id1_, ta2s0_.id as id5_0_, ta2s0_.kecheng as kecheng5_0_, ta2s0_.ids as ids5_0_ from test_ssh.ta2 ta2s0_ where ta2s0_.ids=?
Hibernate: select ta2s0_.ids as ids1_, ta2s0_.id as id1_, ta2s0_.id as id5_0_, ta2s0_.kecheng as kecheng5_0_, ta2s0_.ids as ids5_0_ from test_ssh.ta2 ta2s0_ where ta2s0_.ids=?
Hibernate: select ta2s0_.ids as ids1_, ta2s0_.id as id1_, ta2s0_.id as id5_0_, ta2s0_.kecheng as kecheng5_0_, ta2s0_.ids as ids5_0_ from test_ssh.ta2 ta2s0_ where ta2s0_.ids=?
Hibernate: select ta2s0_.ids as ids1_, ta2s0_.id as id1_, ta2s0_.id as id5_0_, ta2s0_.kecheng as kecheng5_0_, ta2s0_.ids as ids5_0_ from test_ssh.ta2 ta2s0_ where ta2s0_.ids=?
Hibernate: select ta2s0_.ids as ids1_, ta2s0_.id as id1_, ta2s0_.id as id5_0_, ta2s0_.kecheng as kecheng5_0_, ta2s0_.ids as ids5_0_ from test_ssh.ta2 ta2s0_ where ta2s0_.ids=?

[b]问题补充:[/b]
就是想叫它找到 kecheng 这个字段啊,怎么找呢?
[b]问题补充:[/b]
问题就是 怎么找出Ta2表里的 kecheng啊

  • 写回答

4条回答 默认 最新

  • wanghaolovezlq 2009-06-22 08:23
    关注

    [code="java"]

    public ActionForward lists(ActionMapping mapping,ActionForm form,
    HttpServletRequest request,HttpServletResponse response) throws Exception{

    Query query = getSession().createQuery("from Ta2 "); 
    List list =  query.list(); 
    

    request.setAttribute("views", list);

    return mapping.findForward("lis");

    }

    [/code]

    jsp页面改为

    [code="java"]





    ${st.ta1.names}


    ${st.kecheng}


    href=""> src="img_files/del.gif" border=0>



    href=""> src="img_files/edit.gif" border=0>

                            </TR>
                            </c:forEach>
                            </c:when>
                            <c:otherwise>
                                <%response.sendRedirect(request.getContextPath()+"/view.do?method=lists"); %>
                            </c:otherwise>
                            </c:choose>
    

    [/code]

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥30 YOLO检测微调结果p为1
  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题