hibernate 报错 SQL Error: 1062, SQLState: 23000_JAVA_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > JAVA > hibernate 报错 SQL Error: 1062, SQLState: 23000

hibernate 报错 SQL Error: 1062, SQLState: 23000

 2018/4/12 15:38:54  knight_black_bob  程序员俱乐部  我要评论(0)
  • 摘要:hibernate报错SQLError:1062,SQLState:23000第一次插入成功,第二次失败2018-04-1210:50:35.163INFO10708---[pool-1-thread-1]s.spider.govZone.task.SchedulerTask:=====================scheduled====================2018-04-1210:50:35.164INFO10708---[cTaskExecutor-5]s.s
  • 标签:SQL hibernate

?

?

hibernate 报错 SQL Error: 1062, SQLState: 23000

?

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

?

class="java" name="code">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: 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=?
==================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: 23000
2018-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/



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

?

上一篇: Java从零到企业级电商项目实战 下一篇: 没有下一篇了!
发表评论
用户名: 匿名