问题描述
- jstl报错,在网上查了很久还是没能解决,求大神帮忙~~~跪谢~~没c币了
-
报的错:org.apache.jasper.JasperException: javax.el.ELException: Error reading 'stuname' on type model.StuInformationOne_$$_javassist_1
jsp:
<table> <tbody> <c:forEach items="${requestScope.commPage.lists}" var="stu"> <tr> <td class="table-content">${stu.stunameused}</td> <td class="table-content">${stu.stuInformationOne.stuname}</td> </tr> </c:forEach> </tbody> </table>
action:
//查询 public String serchStu() throws Exception { CommPage commPage; StringBuffer hql = new StringBuffer(); hql.append("FROM StuInformationTwo"); session.put("AmaxR", cmaxR); commPage=this.dao.findCommPageByhql(hql.toString(), null, currPage, (Integer)session.get("AmaxR")); requestMap.put("commPage", commPage); System.out.println("commPage"+commPage); return "fa"; }
StuInformationTwo实体类:
package model; /** * StuInformationTwo entity. @author MyEclipse Persistence Tools */ public class StuInformationTwo implements java.io.Serializable { // Fields private Integer id; private StuInformationOne stuInformationOne; private String stunameused; private String stuvld; private String stuhousehold; private String stuccountnature; private String stuspecialty; private String stustuid; private String stugrade; private String stufaculty; private String stuclass; private String stuentrancetime; // Constructors /** default constructor */ public StuInformationTwo() { } /** full constructor */ public StuInformationTwo(StuInformationOne stuInformationOne, String stunameused, String stuvld, String stuhousehold, String stuccountnature, String stuspecialty, String stustuid, String stugrade, String stufaculty, String stuclass, String stuentrancetime) { this.stuInformationOne = stuInformationOne; this.stunameused = stunameused; this.stuvld = stuvld; this.stuhousehold = stuhousehold; this.stuccountnature = stuccountnature; this.stuspecialty = stuspecialty; this.stustuid = stustuid; this.stugrade = stugrade; this.stufaculty = stufaculty; this.stuclass = stuclass; this.stuentrancetime = stuentrancetime; } get,setlue }
StuInformationTwo配置文件:
<hibernate-mapping> <class name="model.StuInformationTwo" table="stu_information_two" catalog="select"> <id name="id" type="java.lang.Integer"> <column name="id" /> <generator class="increment" /> </id> <many-to-one name="stuInformationOne" class="model.StuInformationOne" fetch="select"> <column name="oneid" /> </many-to-one> <property name="stunameused" type="java.lang.String"> <column name="stunameused" /> </property> <property name="stuvld" type="java.lang.String"> <column name="stuvld" /> </property> <property name="stuhousehold" type="java.lang.String"> <column name="stuhousehold" /> </property> <property name="stuccountnature" type="java.lang.String"> <column name="stuccountnature" /> </property> <property name="stuspecialty" type="java.lang.String"> <column name="stuspecialty" /> </property> <property name="stustuid" type="java.lang.String"> <column name="stustuid" /> </property> <property name="stugrade" type="java.lang.String"> <column name="stugrade" /> </property> <property name="stufaculty" type="java.lang.String"> <column name="stufaculty" /> </property> <property name="stuclass" type="java.lang.String"> <column name="stuclass" /> </property> <property name="stuentrancetime" type="java.lang.String"> <column name="stuentrancetime" /> </property> </class> </hibernate-mapping>
StuInformationOne实体类:
package model; import java.util.Date; import java.util.HashSet; import java.util.Set; public class StuInformationOne implements java.io.Serializable { private Integer id; private String stuname; private String stusex; private String stubirthday; private String stunativeplace; private String stunation; private String stucountry; private String stutypeofidentity; private String stuidentity; private String stucverseaschinese; private String stuhealth; private String stupoliticalstatus; private Date date; private Set stuInformationThrs = new HashSet(0); private Set stuFamilyOnes = new HashSet(0); private Set stuInformationTwos = new HashSet(0); private Set stuFamilyTwos = new HashSet(0); public StuInformationOne(String stuname, String stusex, String stubirthday, String stunativeplace, String stunation, String stucountry, String stutypeofidentity, String stuidentity, String stucverseaschinese, String stuhealth, String stupoliticalstatus, Date date, Set stuInformationThrs, Set stuFamilyOnes, Set stuInformationTwos, Set stuFamilyTwos) { this.stuname = stuname; this.stusex = stusex; this.stubirthday = stubirthday; this.stunativeplace = stunativeplace; this.stunation = stunation; this.stucountry = stucountry; this.stutypeofidentity = stutypeofidentity; this.stuidentity = stuidentity; this.stucverseaschinese = stucverseaschinese; this.stuhealth = stuhealth; this.stupoliticalstatus = stupoliticalstatus; this.date = date; this.stuInformationThrs = stuInformationThrs; this.stuFamilyOnes = stuFamilyOnes; this.stuInformationTwos = stuInformationTwos; this.stuFamilyTwos = stuFamilyTwos; } get,set略 }
StuInformationOne配置文件:
<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <!-- Mapping file autogenerated by MyEclipse Persistence Tools --> <hibernate-mapping> <class name="model.StuInformationOne" table="stu_information_one" catalog="select"> <id name="id" type="java.lang.Integer"> <column name="id" /> <generator class="increment" /> </id> <property name="stuname" type="java.lang.String"> <column name="stuname" /> </property> <property name="stusex" type="java.lang.String"> <column name="stusex" /> </property> <property name="stubirthday" type="java.lang.String"> <column name="stubirthday" /> </property> <property name="stunativeplace" type="java.lang.String"> <column name="stunativeplace" /> </property> <property name="stunation" type="java.lang.String"> <column name="stunation" /> </property> <property name="stucountry" type="java.lang.String"> <column name="stucountry" /> </property> <property name="stutypeofidentity" type="java.lang.String"> <column name="stutypeofidentity" /> </property> <property name="stuidentity" type="java.lang.String"> <column name="stuidentity" /> </property> <property name="stucverseaschinese" type="java.lang.String"> <column name="stucverseaschinese" /> </property> <property name="stuhealth" type="java.lang.String"> <column name="stuhealth" /> </property> <property name="stupoliticalstatus" type="java.lang.String"> <column name="stupoliticalstatus" /> </property> <property name="date" type="java.util.Date"> <column name="date" length="10" /> </property> <set name="stuInformationThrs" inverse="true" cascade="all"> <key> <column name="twoid" /> </key> <one-to-many class="model.StuInformationThr" /> </set> <set name="stuFamilyOnes" inverse="true" cascade="all"> <key> <column name="thrid" /> </key> <one-to-many class="model.StuFamilyOne" /> </set> <set name="stuInformationTwos" inverse="true" cascade="all"> <key> <column name="oneid" /> </key> <one-to-many class="model.StuInformationTwo" /> </set> <set name="stuFamilyTwos" inverse="true" cascade="all"> <key> <column name="fouid" /> </key> <one-to-many class="model.StuFamilyTwo" /> </set> </class> </hibernate-mapping>
解决方案
猜测是页面解析不了${stu.stuInformationOne}对象,而是把stuInformationOne解析成一个字符串。
你可以重写stuInformationOne的toString方法来验证一下。
个人觉得hibernate的关联查询有的时候真的很不方便,取值时还会报错(session已关闭)。还不如直接写sql语句。
解决方案二:
开启lazy模式。。。。
时间: 2024-10-28 07:11:56