spring-projects / spring-projects/spring-data-relational
Enable Microsoft SQL Server Dialect to work with primary key default.
@christophstrobl is already working on this.
Since Mar 20, 2026.
- Dominant language
- Java
- Stars
- 827
- Forks
- 394
- PR merge metrics
- No merged PRs in 30d
Description
Currently the SqlServerDialect requires use of IDENTITY to retrieve inserted id values.
ID INT IDENTITY PRIMARY KEY
The above can be tricky when attempting to e.g. upsert values (see: #493) as it requires additional statements SET IDENTITY_INSERT <table_name> ON|OFF to allow inserting values into the ID column.
Using a different column declaration approach neglects the need of the additional identity insert instructions.
ID INT PRIMARY KEY DEFAULT (NEXT VALUE FOR <seqence_name>)
Unfortunately using key defaults does not return the obtained value unless explicitly advised using OUTPUT INSERTED.<column_name>.
The SqlServerDialect should allow users to choose their identity strategy based on which OUTPUT INSERTED is included in the statement or not.
Running additional commands to en/disable IDENTITY_INSERT before/after the statement is in the users responsibility when choosing IDENTITY. They should not be run by data-jdbc as part of an insert/upsert attempt.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.