Java论坛网»Java技术»求助:Hibernate,空指针错误

求助:Hibernate,空指针错误

问?:
当数据库某个字段为空时,就报空指针错误
可我没引用这个空的字段啊
只有parent_id这字段为空,其他都不空
public void query() throws HibernateException {
session = HibernateSessionFactory.currentSession();
Query query = session.createQuery("from TSysModule a");
List list = query.list();
Iterator it = list.iterator();
TSysModule module;
while (it.hasNext()) {
module = (TSysModule)it.next();
System.out.println(">>>>>>>>>>>"+module.getId().getModuleName());
}

}
答!: 1:
你的parent_id是不是配置为不能为空的

看看配置文件
答!: 2:
我没设啊,默认应该可以为空吧
<hibernate-mapping>
<class name="org.wangluo.framework.vo.TSysModule" table="T_SYS_MODULE" schema="dbo" catalog="wangluo">
<composite-id name="id" class="org.wangluo.framework.vo.TSysModuleId" >
<key-property name="moduleId" type="string">
<column name="MODULE_ID" length="10" />
</key-property>
<key-property name="parentModuleId" type="string" >
<column name="PARENT_MODULE_ID" length="10" />
</key-property>
<key-property name="moduleName" type="string">
<column name="MODULE_NAME" length="20" />
</key-property>
<key-property name="leaf" type="string">
<column name="LEAF" length="50" />
</key-property>
<key-property name="listOrder" type="string">
<column name="LIST_ORDER" length="50" />
</key-property>
<key-property name="visible" type="string">
<column name="VISIBLE" length="50" />
</key-property>
</composite-id>
</class>
</hibernate-mapping>
答!: 3:
我打印出来,发现list就有的值为空了
Query query = session.createQuery("from TSysModule a");

List list = query.list();
答!: 4:
<composite-id name="id" class="org.wangluo.framework.vo.TSysModuleId" >

这里你使用的是联合主键,相关联的类必须实现equals()和hashCode()两个方法,两个表互相关联,在查询数据的时候默认的级联查询如果查询到有空字段的就会报错
答!: 5:
那这要怎么解决啊?
答!: 6:
怎么没人啊
答!: 7:
自己解决了
答!: 8:
怎么解决的?? 怎么解决的?? 我也遇到这个问题!
我们做数据库接口,人家是很早的数据库,几乎每张表都没有主键,
我就把所有字段作为联合主键(都是为了<id>元素),怎么解决的???

相关JAVA教程:
请教一个Hibernate的AssertionFailure问题
weblogic上连接ms sql连接池错误
求助---加载图片时怎样设置路径?
跨页面的事务问题
求助---加载图片时怎样设置路径?
请各位大侠指点一下,数据连接的问题!
JTree如何编辑节点,大家帮忙看看
各位高手!好,怎么在JButton中设置标题的布局啊!
想学XML,看什么书比较好?
求助:jbuilder2006运行struts程序出错
Weblogic 下 关于ejb的一个问题
求救!!`各位高手能不能提供些学习JAVA方面的好网站