hibernate多对一关联配置后,hql查询报空,求大神帮助!!

only小白 2015-05-02 10:54:42
学生表student,有外键字段BeLongSchool,BelonngClass,BelongZy,BelongXb,对应school表,clas表,zhuangye表和xibu表。
下面是student映射实体类和配置文件

package org.model;

import java.util.HashSet;
import java.util.Set;

/**
* Student entity. @author MyEclipse Persistence Tools
*/

public class Student implements java.io.Serializable {

// Fields

private String stuId;
private Clas clas;
private School school;
private Xibu xibu;
private Zhuangye zhuangye;
private String name;
private String sex;
private Integer age;
private String politicalStatus;
private Integer xq;
private String adress;
private String tel;
private Short state;
private Short sfBp;
private Set kwmanages = new HashSet(0);

// Constructors

/** default constructor */
public Student() {
}

/** minimal constructor */
public Student(String stuId, Clas clas, School school, Xibu xibu,
Zhuangye zhuangye, String name, String sex, Integer age,
String politicalStatus, Integer xq, String adress, String tel,
Short sfBp) {
this.stuId = stuId;
this.clas = clas;
this.school = school;
this.xibu = xibu;
this.zhuangye = zhuangye;
this.name = name;
this.sex = sex;
this.age = age;
this.politicalStatus = politicalStatus;
this.xq = xq;
this.adress = adress;
this.tel = tel;
this.sfBp = sfBp;
}

/** full constructor */
public Student(String stuId, Clas clas, School school, Xibu xibu,
Zhuangye zhuangye, String name, String sex, Integer age,
String politicalStatus, Integer xq, String adress, String tel,
Short state, Short sfBp, Set kwmanages) {
this.stuId = stuId;
this.clas = clas;
this.school = school;
this.xibu = xibu;
this.zhuangye = zhuangye;
this.name = name;
this.sex = sex;
this.age = age;
this.politicalStatus = politicalStatus;
this.xq = xq;
this.adress = adress;
this.tel = tel;
this.state = state;
this.sfBp = sfBp;
this.kwmanages = kwmanages;
}

// Property accessors

public String getStuId() {
return this.stuId;
}

public void setStuId(String stuId) {
this.stuId = stuId;
}

public Clas getClas() {
return this.clas;
}

public void setClas(Clas clas) {
this.clas = clas;
}

public School getSchool() {
return this.school;
}

public void setSchool(School school) {
this.school = school;
}

public Xibu getXibu() {
return this.xibu;
}

public void setXibu(Xibu xibu) {
this.xibu = xibu;
}

public Zhuangye getZhuangye() {
return this.zhuangye;
}

public void setZhuangye(Zhuangye zhuangye) {
this.zhuangye = zhuangye;
}

public String getName() {
return this.name;
}

public void setName(String name) {
this.name = name;
}

public String getSex() {
return this.sex;
}

public void setSex(String sex) {
this.sex = sex;
}

public Integer getAge() {
return this.age;
}

public void setAge(Integer age) {
this.age = age;
}

public String getPoliticalStatus() {
return this.politicalStatus;
}

public void setPoliticalStatus(String politicalStatus) {
this.politicalStatus = politicalStatus;
}

public Integer getXq() {
return this.xq;
}

public void setXq(Integer xq) {
this.xq = xq;
}

public String getAdress() {
return this.adress;
}

public void setAdress(String adress) {
this.adress = adress;
}

public String getTel() {
return this.tel;
}

public void setTel(String tel) {
this.tel = tel;
}

public Short getState() {
return this.state;
}

public void setState(Short state) {
this.state = state;
}

public Short getSfBp() {
return this.sfBp;
}

public void setSfBp(Short sfBp) {
this.sfBp = sfBp;
}

public Set getKwmanages() {
return this.kwmanages;
}

public void setKwmanages(Set kwmanages) {
this.kwmanages = kwmanages;
}

}



<?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="org.model.Student" table="student" catalog="kwmanage">
<id name="stuId" type="java.lang.String">
<column name="StuId" length="9" />
<generator class="assigned" />
</id>
<many-to-one name="clas" class="org.model.Clas" fetch="select">
<column name="BelongClass" length="7" not-null="true">
<comment>所在班级</comment>
</column>
</many-to-one>
<many-to-one name="school" class="org.model.School" fetch="select">
<column name="BelongSchool" length="3" not-null="true">
<comment>所属学校</comment>
</column>
</many-to-one>
<many-to-one name="xibu" class="org.model.Xibu" fetch="select">
<column name="BelongXb" length="2" not-null="true">
<comment>所属系部</comment>
</column>
</many-to-one>
<many-to-one name="zhuangye" class="org.model.Zhuangye" fetch="select">
<column name="BelongZy" length="1" not-null="true">
<comment>所属专业</comment>
</column>
</many-to-one>
<property name="name" type="java.lang.String">
<column name="Name" length="20" not-null="true">
<comment>姓名</comment>
</column>
</property>
<property name="sex" type="java.lang.String">
<column name="Sex" length="2" not-null="true">
<comment>性别</comment>
</column>
</property>
<property name="age" type="java.lang.Integer">
<column name="Age" not-null="true">
<comment>年龄</comment>
</column>
</property>
<property name="politicalStatus" type="java.lang.String">
<column name="PoliticalStatus" length="20" not-null="true">
<comment>政治面貌</comment>
</column>
</property>
<property name="xq" type="java.lang.Integer">
<column name="Xq" not-null="true">
<comment>所属学期</comment>
</column>
</property>
<property name="adress" type="java.lang.String">
<column name="Adress" length="20" not-null="true">
<comment>家庭住址</comment>
</column>
</property>
<property name="tel" type="java.lang.String">
<column name="Tel" length="11" not-null="true">
<comment>联系电话</comment>
</column>
</property>
<property name="state" type="java.lang.Short">
<column name="State" />
</property>
<property name="sfBp" type="java.lang.Short">
<column name="SfBp" not-null="true" />
</property>
<set name="kwmanages" inverse="true">
<key>
<column name="StuId" length="9" not-null="true">
<comment>学号</comment>
</column>
</key>
<one-to-many class="org.model.Kwmanage" />
</set>
</class>
</hibernate-mapping>

hql查询报空
//分页显示学生信息集接口实现
public List findAllStu(int pageNow, int pageSize) {
// TODO Auto-generated method stub
try{
Session session=getHibernateTemplate().getSessionFactory().openSession();
Transaction ts=session.beginTransaction();
Query query=session.createQuery("from Student s order by s.stuId");
int firstResult=(pageNow-1)*pageSize;
query.setFirstResult(firstResult);
query.setMaxResults(pageSize);

List list=query.list();

ts.commit();
session.close();
session=null;
return list;
}
catch(Exception e){
e.printStackTrace();
return null;
}

}




执行到list就异常报空


下面是错误信息

java.lang.NullPointerException
at org.hibernate.tuple.AbstractEntityTuplizer.createProxy(AbstractEntityTuplizer.java:372)
at org.hibernate.persister.entity.AbstractEntityPersister.createProxy(AbstractEntityPersister.java:3121)
at org.hibernate.event.def.DefaultLoadEventListener.createProxyIfNecessary(DefaultLoadEventListener.java:232)
at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:173)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:87)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:862)
at org.hibernate.impl.SessionImpl.internalLoad(SessionImpl.java:830)
at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:266)
at org.hibernate.type.EntityType.resolve(EntityType.java:303)
at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:116)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:842)
at org.hibernate.loader.Loader.doQuery(Loader.java:717)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.doList(Loader.java:2145)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029)
at org.hibernate.loader.Loader.list(Loader.java:2024)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:375)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:308)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:153)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1106)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at org.Dao.imp.StuDaoImp.findAllStu(StuDaoImp.java:50)
at org.Service.Imp.StuServiceImp.findAllStu(StuServiceImp.java:51)
...全文
171 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

24,923

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 Apache
社区管理员
  • Apache
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧