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
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值