As I had mentioned in this post JPA SET IDENTITY_INSERT not working that I was successful in using the
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.