码迷,mamicode.com
首页 > 数据库 > 详细

hibernate映射实体类查询时数据库空字段赋值给实体类报错的问题

时间:2018-11-15 11:00:34      阅读:427      评论:0      收藏:0      [点我收藏+]

标签:mapping   reset   pointer   his   element   null   dma   赋值   val   

  因为一直报实体类空异常,去网上查了资料只查到了并没有查到数据库空值时不给实体类赋值的属性,只有这两个属性

技术分享图片

  这两个属性时设置 实体类有空字段插入或更新 数据库时空属性为默认值

异常

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映射实体类查询时数据库空字段赋值给实体类报错的问题

标签:mapping   reset   pointer   his   element   null   dma   赋值   val   

原文地址:https://www.cnblogs.com/hfx123/p/9962076.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!