简体   繁体   English

在SQL Server表上设置IDENTITY_INSERT时出错

[英]Error when setting IDENTITY_INSERT on sql server table

As I had mentioned in this post JPA SET IDENTITY_INSERT not working that I was successful in using the 正如我在这篇文章中提到的, JPA SET IDENTITY_INSERT无法正常工作 ,说明我已成功使用

SET IDENTITY_INSERT

query for my purposes. 查询我的目的。 But today after I have managed to configure connection pooling i am getting this type of error. 但是今天,在我设法配置连接池之后,我遇到了这种类型的错误。

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)

Can anyone suggest something to resolve this error? 任何人都可以提出一些解决此错误的建议吗?

Using Identity Insert is a symmetrical command, after turning it on, you must turn it off. 使用“身份插入”是一个对称命令,将其打开后,必须将其关闭。 For example. 例如。

Set Identity_Insert ErrorLog On

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

Set Identity_Insert ErrorLog Off

Hope that helps. 希望能有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM