null id in com.rocky.** entry 错误处理

1. 概述

使用hibernate往mysql数据库插入记录出错如下

10:37:57,364 ERROR [AssertionFailure] an assertion failure occured (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session)
org.hibernate.AssertionFailure: null id in com.rocky.console.domain.Downinfo entry (don't flush the Session after an exception occurs)

 

2. 分析

对比:

Downinfo对象中id是long类型 ————数据库表downinfo中id字段bigint类型,

<generator class="native"/>————数据库中设置了自增

看来并没有错

代码断点发现 与表中非空字段对应的bean属性为null,而表中又没有设置默认值(如""或0之类),

这是出错的原因 只不过hibernate提示不准确

 

3.解决方案

将数据库表中字段not null 部分设置默认值或者 在bean中对相应属性做默认赋值。

done

转载于:https://www.cnblogs.com/rocky-fang/p/6840055.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值