hibernate映射实体类查询时数据库空字段赋值给实体类报错的问题
Posted 有梦想,就要捍卫它
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了hibernate映射实体类查询时数据库空字段赋值给实体类报错的问题相关的知识,希望对你有一定的参考价值。
因为一直报实体类空异常,去网上查了资料只查到了并没有查到数据库空值时不给实体类赋值的属性
异常
org.hibernate.InvalidMappingException: Could not parse mapping document from resource cn/pojo/EmpDao.xml at org.hibernate.cfg.Configuration.addResource(Configuration.java:616) at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1635) at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1603) at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1582) at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1556) at org.hibernate.cfg.Configuration.configure(Configuration.java:1476) at org.hibernate.cfg.Configuration.configure(Configuration.java:1462) at cn.tool.HibernateUtil.<clinit>(HibernateUtil.java:16) at cn.service.EmpService.findEmpById(EmpService.java:16) at cn.Test.main(Test.java:9) Caused by: org.hibernate.InvalidMappingException: Could not parse mapping document from input stream at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:555) at org.hibernate.cfg.Configuration.addResource(Configuration.java:613) ... 9 more Caused by: org.dom4j.DocumentException: Connection reset Nested exception: Connection reset at org.dom4j.io.SAXReader.read(SAXReader.java:484) at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:546) ... 10 more Exception in thread "main" java.lang.NullPointerException at cn.tool.HibernateUtil.currentSession(HibernateUtil.java:29) at cn.service.EmpService.findEmpById(EmpService.java:16) at cn.Test.main(Test.java:9)
于是就加了这段代码
public void setComm(Object comm) { if(comm!=null) this.comm = (double)comm; }
以上是关于hibernate映射实体类查询时数据库空字段赋值给实体类报错的问题的主要内容,如果未能解决你的问题,请参考以下文章
hibernate映射postgreSQL数据库中的表时,表名是大写的时候为啥hibernate不能映射实体