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;
    }
posted @ 2018-11-15 10:33  不--易  阅读(1388)  评论(0编辑  收藏  举报