[英]Cannot insert explicit value for identity column in table 'Employee' when IDENTITY_INSERT is set to OFF
[英]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.