首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

SqlServer : java.sql.SQLException: 没法将 NULL 值插入列

2012-10-26 
SqlServer : java.sql.SQLException: 无法将 NULL 值插入列调用ibatis的DAO:2008-9-23 15:43:09 org.apach

SqlServer : java.sql.SQLException: 无法将 NULL 值插入列
调用ibatis的DAO:
2008-9-23 15:43:09 org.apache.catalina.core.ApplicationContext log
信息: org.springframework.dao.DataIntegrityViolationException: SqlMapClient operation; SQL [];  
--- The error occurred in com/miracle/dm/sysmgr/log/sqlmapxml/Log_SqlMap.xml. 
--- The error occurred while applying a parameter map. 
--- Check the insertLog-InlineParameterMap. 
--- Check the statement (update failed). 
--- Cause: java.sql.SQLException: 无法将 NULL 值插入列 'log_id',表 'mloa.dbo.tb_log';该列不允许空值。INSERT 失败。; nested exception is com.ibatis.common.jdbc.exception.NestedSQLException:  
--- The error occurred in com/miracle/dm/sysmgr/log/sqlmapxml/Log_SqlMap.xml. 
--- The error occurred while applying a parameter map. 
--- Check the insertLog-InlineParameterMap. 
--- Check the statement (update failed). 
--- Cause: java.sql.SQLException: 无法将 NULL 值插入列 'log_id',表 'mloa.dbo.tb_log';该列不允许空值。INSERT 失败。



调用hibernate的DAO:
Hibernate: insert into TB_LOG (LOG_TYPE, LOG_USERID, USER_NAME, LOG_TIME, MODULE_CODE, LOG_CONTENT, OPER_CODE, REMARK) values (?, ?, ?, ?, ?, ?, ?, ?)
[@APPNAME@] WARN [http-80-8] JDBCExceptionReporter.logExceptions(77) | SQL Error: 515, SQLState: 23000
[@APPNAME@] ERROR [http-80-8] JDBCExceptionReporter.logExceptions(78) | 无法将 NULL 值插入列 'log_id',表 'mloa.dbo.tb_log';该列不允许空值。INSERT 失败。
org.springframework.dao.DataIntegrityViolationException: could not insert: [com.miracle.dm.sysmgr.log.model.LogInfo]; nested exception is org.hibernate.exception.ConstraintViolationException: could not insert: [com.miracle.dm.sysmgr.log.model.LogInfo]
at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:628)
at org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:408)
Log.hbm.xml中主键id的配置:
                <id name="logId"  column="LOG_ID">
   <generator class="native"/>
  </id>
按理说配置为native则会根据数据库自动帮你选择自增的类型,可为何还是报错?


直接采用查询分析器执行代码:

INSERT INTO TB_LOG     (LOG_TYPE ,       LOG_USERID ,       USER_NAME ,       LOG_TIME ,       MODULE_CODE ,       LOG_CONTENT ,       OPER_CODE ,       REMARK     )      VALUES     ('DocumentAction' ,   '4212100010160', 'admin', '2008-09-23 15:43:09.156', 'Module1', 'admin用户新增文档ID_:547', 'ADD' ,'') 
一样出现问题,显示结果:无法将 NULL 值插入列 'log_id',表 'mloa.dbo.tb_log';该列不允许空值。INSERT 失败。

修改sql语句,执行:
INSERT INTO TB_LOG     (log_id,LOG_TYPE ,       LOG_USERID ,       USER_NAME ,       LOG_TIME ,       MODULE_CODE ,       LOG_CONTENT ,       OPER_CODE ,       REMARK     )      VALUES     (     0, 'DocumentAction' ,   '4212100010160', 'admin', '2008-09-23 15:43:09.156', 'Module1', 'admin用户新增文档ID_:547', 'ADD' ,'')  
显示结果:(所影响的行数为 1 行)

解决方法:
    修改数据库中表的字段属性,注意默认值不要填,否则你无法设置标识为是,那么你将看到标识种子,标识递增量都显示为灰色。
   “标识”选择为“是”,“标识种子”为1,“标识递增量”为1



本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/foamflower/archive/2008/09/24/2972566.aspx

热点排行