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

报告相同问题?

悬赏问题

  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图2.0 版本点聚合中Marker的位置无法实时更新,如何解决呢?
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题