ITKeyword,专注技术干货聚合推荐

注册 | 登录

hibernate 报错 SQL Error: 1062, SQLState: 23000

knight_black_bob 分享于

2021腾讯云限时秒杀,爆款1核2G云服务器298元/3年!(领取2860元代金券),
地址https://cloud.tencent.com/act/cps/redirect?redirect=1062

2021阿里云最低价产品入口+领取代金券(老用户3折起),
入口地址https://www.aliyun.com/minisite/goods

推荐:Hibernate中遇到的SQL Error: 156, SQLState: S1000错误

今天遇到这样一个错误 util.JDBCExceptionReporter          77  ) SQL Error: 156, SQLState: S1000 (util.JDBCExceptionReporter          78  ) 在关键字 'us

hibernate 报错 SQL Error: 1062, SQLState: 23000

第一次插入成功,第二次失败

2018-04-12 10:50:35.163

INFO 10708 --- [pool-1-thread-1] s.spider.govZone.task.SchedulerTask

: ===================== scheduled ====================2018-04-12 10:50:35.164

INFO 10708 --- [cTaskExecutor-5] s.s.govZone.linstener.EventListener

: ========================showandshare.spider.govZone.event.CityEvent[source=showandshare.spider.govZone.service.impl.ProcessServiceImpl@777d0398]========================================[{"cityCode":"620100000000","cityId":0,"cityKey":"6201","cityName":"兰州市","cityUrl":"http://www.stats.gov.cn/tjsj/tjbz/tjyqhdmhcxhfdm/2016/62/6201.html","countryList":[],"provinceKey":"62"},{"cityCode":"620200000000","cityId":0,"cityKey":"6202","cityName":"嘉峪关市","cityUrl":"http://www.stats.gov.cn/tjsj/tjbz/tjyqhdmhcxhfdm/2016/62/6202.html","countryList":[],"provinceKey":"62"},{"cityCode":"620300000000","cityId":0,"cityKey":"6203","cityName":"金昌市","cityUrl":"http://www.stats.gov.cn/tjsj/tjbz/tjyqhdmhcxhfdm/2016/62/6203.html","countryList":[],"provinceKey":"62"},{"cityCode":"620400000000","cityId":0,"cityKey":"6204","cityName":"白银市","cityUrl":"http://www.stats.gov.cn/tjsj/tjbz/tjyqhdmhcxhfdm/2016/62/6204.html","countryList":[],"provinceKey":"62"},{"cityCode":"620500000000","cityId":0,"cityKey":"6205","cityName":"天水市","cityUrl":"http://www.stats.gov.cn/tjsj/tjbz/tjyqhdmhcxhfdm/2016/62/6205.html","countryList":[],"provinceKey":"62"},{"cityCode":"620600000000","cityId":0,"cityKey":"6206","cityName":"武威市","cityUrl":"http://www.stats.gov.cn/tjsj/tjbz/tjyqhdmhcxhfdm/2016/62/6206.html","countryList":[],"provinceKey":"62"},{"cityCode":"620700000000","cityId":0,"cityKey":"6207","cityName":"张掖市","cityUrl":"http://www.stats.gov.cn/tjsj/tjbz/tjyqhdmhcxhfdm/2016/62/6207.html","countryList":[],"provinceKey":"62"},{"cityCode":"620800000000","cityId":0,"cityKey":"6208","cityName":"平凉市","cityUrl":"http://www.stats.gov.cn/tjsj/tjbz/tjyqhdmhcxhfdm/2016/62/6208.html","countryList":[],"provinceKey":"62"},{"cityCode":"620900000000","cityId":0,"cityKey":"6209","cityName":"酒泉市","cityUrl":"http://www.stats.gov.cn/tjsj/tjbz/tjyqhdmhcxhfdm/2016/62/6209.html","countryList":[],"provinceKey":"62"},{"cityCode":"621000000000","cityId":0,"cityKey":"6210","cityName":"庆阳市","cityUrl":"http://www.stats.gov.cn/tjsj/tjbz/tjyqhdmhcxhfdm/2016/62/6210.html","countryList":[],"provinceKey":"62"},{"cityCode":"621100000000","cityId":0,"cityKey":"6211","cityName":"定西市","cityUrl":"http://www.stats.gov.cn/tjsj/tjbz/tjyqhdmhcxhfdm/2016/62/6211.html","countryList":[],"provinceKey":"62"},{"cityCode":"621200000000","cityId":0,"cityKey":"6212","cityName":"陇南市","cityUrl":"http://www.stats.gov.cn/tjsj/tjbz/tjyqhdmhcxhfdm/2016/62/6212.html","countryList":[],"provinceKey":"62"},{"cityCode":"622900000000","cityId":0,"cityKey":"6229","cityName":"临夏回族自治州","cityUrl":"http://www.stats.gov.cn/tjsj/tjbz/tjyqhdmhcxhfdm/2016/62/6229.html","countryList":[],"provinceKey":"62"},{"cityCode":"623000000000","cityId":0,"cityKey":"6230","cityName":"甘南藏族自治州","cityUrl":"http://www.stats.gov.cn/tjsj/tjbz/tjyqhdmhcxhfdm/2016/62/6230.html","countryList":[],"provinceKey":"62"}]=========================================================1======================={"cityCode":"620100000000","cityId":0,"cityKey":"6201","cityName":"兰州市","cityUrl":"http://www.stats.gov.cn/tjsj/tjbz/tjyqhdmhcxhfdm/2016/62/6201.html","countryList":[],"provinceKey":"62"}Hibernate: sel

推荐:JPA hibernate spring repository pgsql java 工程(二):sql文件导入数据,测试数据

使用jpa保存查询数据都很方便,除了在代码中加入数据外,可以使用sql进行导入。目前我只会一种方法,把数据集中在一个sql文件中。 而且数据在导入中常常具有先后

ect province0_.province_id as province1_2_, province0_.province_code as province2_2_, province0_.province_key as province3_2_, province0_.province_name as province4_2_, province0_.province_url as province5_2_ from t_province province0_ where province0_.province_key=?Hibernate: select citylist0_.province_id as province7_0_0_, citylist0_.city_id as city_id1_0_0_, citylist0_.city_id as city_id1_0_1_, citylist0_.city_code as city_cod2_0_1_, citylist0_.city_key as city_key3_0_1_, citylist0_.city_name as city_nam4_0_1_, citylist0_.city_url as city_url5_0_1_, citylist0_.province_id as province7_0_1_, citylist0_.province_key as province6_0_1_ from t_city citylist0_ where citylist0_.province_id=?==================2======================{"cityList":[],"provinceCode":"62","provinceId":28,"provinceKey":"62","provinceName":"甘肃省","provinceUrl":"http://www.stats.gov.cn/tjsj/tjbz/tjyqhdmhcxhfdm/2016/62.html"}===================3====================={"cityCode":"620100000000","cityId":0,"cityKey":"6201","cityName":"兰州市","cityUrl":"http://www.stats.gov.cn/tjsj/tjbz/tjyqhdmhcxhfdm/2016/62/6201.html","countryList":[],"provinceKey":"62"}Hibernate: insert into t_city (city_code, city_key, city_name, city_url, province_id, province_key) values (?, ?, ?, ?, ?, ?)=================1======================={"cityCode":"620200000000","cityId":0,"cityKey":"6202","cityName":"嘉峪关市","cityUrl":"http://www.stats.gov.cn/tjsj/tjbz/tjyqhdmhcxhfdm/2016/62/6202.html","countryList":[],"provinceKey":"62"}Hibernate: select province0_.province_id as province1_2_, province0_.province_code as province2_2_, province0_.province_key as province3_2_, province0_.province_name as province4_2_, province0_.province_url as province5_2_ from t_province province0_ where province0_.province_key=?Hibernate: select citylist0_.province_id as province7_0_0_, citylist0_.city_id as city_id1_0_0_, citylist0_.city_id as city_id1_0_1_, citylist0_.city_code as city_cod2_0_1_, citylist0_.city_key as city_key3_0_1_, citylist0_.city_name as city_nam4_0_1_, citylist0_.city_url as city_url5_0_1_, citylist0_.province_id as province7_0_1_, citylist0_.province_key as province6_0_1_ from t_city citylist0_ where citylist0_.province_id=?Hibernate: select countrylis0_.city_id as city_id7_1_0_, countrylis0_.country_id as country_1_1_0_, countrylis0_.country_id as country_1_1_1_, countrylis0_.city_key as city_key2_1_1_, countrylis0_.country_code as country_3_1_1_, countrylis0_.country_key as country_4_1_1_, countrylis0_.country_name as country_5_1_1_, countrylis0_.country_url as country_6_1_1_, countrylis0_.city_id as city_id7_1_1_ from t_country countrylis0_ where countrylis0_.city_id=?==================2======================{"cityList":[{"cityCode":"620100000000","cityId":18,"cityKey":"6201","cityName":"兰州市","cityUrl":"http://www.stats.gov.cn/tjsj/tjbz/tjyqhdmhcxhfdm/2016/62/6201.html","countryList":[],"provinceKey":"62"}],"provinceCode":"62","provinceId":28,"provinceKey":"62","provinceName":"甘肃省","provinceUrl":"http://www.stats.gov.cn/tjsj/tjbz/tjyqhdmhcxhfdm/2016/62.html"}===================3====================={"cityCode":"620200000000","cityId":0,"cityKey":"6202","cityName":"嘉峪关市","cityUrl":"http://www.stats.gov.cn/tjsj/tjbz/tjyqhdmhcxhfdm/2016/62/6202.html","countryList":[],"provinceKey":"62"}Hibernate: insert into t_city (city_code, city_key, city_name, city_url, province_id, province_key) values (?, ?, ?, ?, ?, ?)2018-04-12 10:50:36.869

WARN 10708 --- [cTaskExecutor-5] o.h.engine.jdbc.spi.SqlExceptionHelper

: SQL Error: 1062, SQLState: 230002018-04-12 10:50:36.869 ERROR 10708 --- [cTaskExecutor-5] o.h.engine.jdbc.spi.SqlExceptionHelper

: Duplicate entry '28' for key 'UK_itaid0sldsu35lk9mkp86b3q3'2018-04-12 10:50:36.922 ERROR 10708 --- [cTaskExecutor-5] s.spider.govZone.event.CityEvent

: org.hibernate.exception.ConstraintViolationException: could not execute statement

错误原因:

unique = false ,我写了 true ,这里面的 false 是非唯一外键的意思

@JsonIgnore

@JSONField(serialize = false)

@ManyToOne(cascade = CascadeType. REFRESH, targetEntity = Province.class

, fetch = FetchType.EAGER)

@JoinColumn(name = "province_id",

unique = false, nullable = false, updatable = false ,insertable = true )

@NotFound(action=NotFoundAction.IGNORE)

@Cascade(value = { org.hibernate.annotations.CascadeType.SAVE_UPDATE })

private Province parentProvince;

捐助开发者

在兴趣的驱动下,写一个免费的东西,有欣喜,也还有汗水,希望你喜欢我的作品,同时也能支持一下。 当然,有钱捧个钱场(支持支付宝和微信 以及扣扣群),没钱捧个人场,谢谢各位。

个人主页:http://knight-black-bob.iteye.com/

谢谢您的赞助,我会做的更好!

推荐:hibernate在DB2数据库上使用报DB2 SQL error: SQLCODE: -104, SQLSTATE: 42601的解决

     前一段时间在做一个项目时,遇到同样的代码在连接oracle的时候正常,在连接DB2数据库的时候出现异常不说,后台哗哗的报错.......直接上图吧: [myProject]

    hibernate 报错 SQL Error: 1062, SQLState: 23000   第一次插入成功,第二次失败   2018-04-12 10:50:35.163 INFO 10708 --- [pool-1-thread-1] s.spider.govZone.task.SchedulerTask

相关阅读排行


相关内容推荐

最新文章

×

×

请激活账号

为了能正常使用评论、编辑功能及以后陆续为用户提供的其他产品,请激活账号。

您的注册邮箱: 修改

重新发送激活邮件 进入我的邮箱

如果您没有收到激活邮件,请注意检查垃圾箱。