Search code examples
sql-serverspring-data-jdbc

Update referenced aggregates using SQL Server fails with ´Cannot insert ... when IDENTITY_INSERT is set to OFF´


We are using latest Spring Data JDBC milestone (1.1.0.M3) together with SQL Server.

Updating referenced aggregates (not the aggregate root itself) - fails with: com.microsoft.sqlserver.jdbc.SQLServerException: Cannot insert explicit value for identity column in table 'mytable' when IDENTITY_INSERT i set to OFF

Updating the aggregate root itself works OK.

Any ideas or suggestions? We are locked to using SQL Server. Note that the above works with H2 in-mem DB.


Solution

  • Spring Data JDBC doesn't support MS-SqlServer yet.

    The currently blocking problem is that it doesn't allow insertion of IDs in columns that are declared as IDENTITY.

    There is an issue for that: https://jira.spring.io/browse/DATAJDBC-278

    You probably don't need the id on the referenced entity though. If you remove it the problem should go away.