Oracle主鍵異常處理

來源:互聯網
上載者:User

標籤:rate   date   cat   oracle主鍵   ror   stand   bsp   values   strategy   

Hibernate: insert into test1.WarnWeather (WAREA, wdate, WDAYS, WINFO, WTYPE, WNO) values (?, ?, ?, ?, ?, ?)
Hibernate: select weathers0_.WNO as WNO1_0_, weathers0_.WAREA as WAREA2_0_, weathers0_.wdate as wdate3_0_, weathers0_.WDAYS as WDAYS4_0_, weathers0_.WINFO as WINFO5_0_, weathers0_.WTYPE as WTYPE6_0_ from test1.WarnWeather weathers0_
Hibernate: insert into test1.WarnWeather (WAREA, wdate, WDAYS, WINFO, WTYPE, WNO) values (?, ?, ?, ?, ?, ?)
ERROR SqlExceptionHelper ORA-00001: 違反唯一約束條件 (TEST1.SYS_C0011549)

ERROR ExceptionMapperStandardImpl HHH000346: Error during managed flush [org.hibernate.exception.ConstraintViolationException: could not execute statement]

 

異常問題:

用戶端只能插入一條資料,當插入第二條資料時出現異常 ERROR SqlExceptionHelper ORA-00001: 違反唯一約束條件 (TEST1.SYS_C0011549)

 

原因:在實體類中沒有配置Oracle的id主鍵導致Oracle主鍵的衝突

 

解決方案:在實體類中添加註解的序列

//@GeneratedValue中generator裡面的值對應@SequenceGenerator中name裡面的值(可以隨便定義但一定要相同),
//sequenceName是建立的sequence名字(對應資料庫中建立的序列名),allocationSize表示序列自增長的大小為1
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator="seq")
@SequenceGenerator(name="seq", sequenceName="SEQ_WEATHER",allocationSize = 1)

Oracle主鍵異常處理

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.