簡體   English   中英

在SQL Server表上設置IDENTITY_INSERT時出錯

[英]Error when setting IDENTITY_INSERT on sql server table

正如我在這篇文章中提到的, JPA SET IDENTITY_INSERT無法正常工作 ,說明我已成功使用

SET IDENTITY_INSERT

查詢我的目的。 但是今天,在我設法配置連接池之后,我遇到了這種類型的錯誤。

java.sql.SQLException: IDENTITY_INSERT is already ON for table 'mydb.dbo.[table1]'. Cannot perform SET operation for table 'dbo.[table2]'.
2015-03-11 15:52:36,126 WARN  org.hibernate.util.JDBCExceptionReporter.logExceptions:233 - SQL Error: 544, SQLState: 23000
2015-03-11 15:52:36,127 ERROR org.hibernate.util.JDBCExceptionReporter.logExceptions:234 - Cannot insert explicit value for identity column in table '[table2]' when IDENTITY_INSERT is set to OFF.
2015-03-11 15:52:36,128 ERROR   org.hibernate.event.def.AbstractFlushingEventListener.performExecutions:324 - Could not synchronize database state with session
org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
at     org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:96)

任何人都可以提出一些解決此錯誤的建議嗎?

使用“身份插入”是一個對稱命令,將其打開后,必須將其關閉。 例如。

Set Identity_Insert ErrorLog On

Insert  Into ErrorLog
        ( LineNumber, ErrorMessage )
Values  ( 0, 'Test 1' ) ,
        ( 1, 'Test 2' )

Set Identity_Insert ErrorLog Off

希望能有所幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM