[hibernate-issues] [JIRA] (HHH-13970) SQL Server needs special handling for Identity column inserts

IT Support (JIRA) jira at hibernate.atlassian.net
Thu Apr 23 00:14:45 EDT 2020


IT Support ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%3A7c7fc415-3805-43c8-9dfa-7cbe1117db94 ) *updated* an issue

Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiNTlhMTA4MGE2N2IzNGFiZDg5ZGY5MDMwZTUwNjBlY2QiLCJwIjoiaiJ9 ) / Sub-task ( https://hibernate.atlassian.net/browse/HHH-13970?atlOrigin=eyJpIjoiNTlhMTA4MGE2N2IzNGFiZDg5ZGY5MDMwZTUwNjBlY2QiLCJwIjoiaiJ9 ) HHH-13970 ( https://hibernate.atlassian.net/browse/HHH-13970?atlOrigin=eyJpIjoiNTlhMTA4MGE2N2IzNGFiZDg5ZGY5MDMwZTUwNjBlY2QiLCJwIjoiaiJ9 ) SQL Server needs special handling for Identity column inserts ( https://hibernate.atlassian.net/browse/HHH-13970?atlOrigin=eyJpIjoiNTlhMTA4MGE2N2IzNGFiZDg5ZGY5MDMwZTUwNjBlY2QiLCJwIjoiaiJ9 )

Change By: IT Support ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%3A7c7fc415-3805-43c8-9dfa-7cbe1117db94 )

SQL Server Identity inserts are different than in other databases, an error message is generated when the {{org.hibernate.dialect.SQLServerDialect}} is updated to return {{true}} from {{supportsCompositeNestedIdentityColumns()}}(examples from [sql-server-helper.com|http://www.sql-server-helper.com/error-messages/msg-339.aspx])

{noformat}Server: Msg 339, Level 15, State 1, Line 1
DEFAULT or NULL are not allowed as explicit identity
values.{noformat}

The following INSERT statement will generate the error:

{code:sql}INSERT INTO [dbo].[SuperHero] ( [SuperHeroID], [SuperHeroName], [FirstName], [LastName] )
VALUES ( DEFAULT, 'Superman', 'Clark', 'Kent' )

Msg 339, Level 16, State 1, Line 1
DEFAULT or NULL are not allowed as explicit identity values.{code}

Similarly, the following INSERT statement will also generate the error:

{code:sql}INSERT INTO [dbo].[SuperHero] ( [SuperHeroID], [SuperHeroName], [FirstName], [LastName] )
VALUES ( NULL, 'Spiderman', 'Peter', 'Parker' )

Msg 339, Level 16, State 1, Line 1
DEFAULT or NULL are not allowed as explicit identity values.{code}

To avoid this error, when inserting into a table with an IDENTITY column, do not include the IDENTITY column in the INSERT statement and let SQL Server assign the value to this column for each row inserted to the table.

{noformat}INSERT INTO [dbo].[SuperHero] ( [SuperHeroName], [FirstName], [LastName] )
VALUES ( 'Superman', 'Clark', 'Kent' )

INSERT INTO [dbo].[SuperHero] ( [SuperHeroName], [FirstName], [LastName] )
VALUES ( 'Spiderman', 'Peter', 'Parker' ){noformat}

As such the Identity insert generation in the SQL Server Dialects remove the Identity column. [https://hibernate.atlassian.net/browse/HHH-9662|https://hibernate.atlassian.net/browse/HHH-9662|smart-link] reformulates how it all works and now the SQL Server Dialects need to be updated specially.

( https://hibernate.atlassian.net/browse/HHH-13970#add-comment?atlOrigin=eyJpIjoiNTlhMTA4MGE2N2IzNGFiZDg5ZGY5MDMwZTUwNjBlY2QiLCJwIjoiaiJ9 ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-13970#add-comment?atlOrigin=eyJpIjoiNTlhMTA4MGE2N2IzNGFiZDg5ZGY5MDMwZTUwNjBlY2QiLCJwIjoiaiJ9 )

Get Jira notifications on your phone! Download the Jira Cloud app for Android ( https://play.google.com/store/apps/details?id=com.atlassian.android.jira.core&referrer=utm_source%3DNotificationLink%26utm_medium%3DEmail ) or iOS ( https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=EmailNotificationLink&mt=8 ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100125- sha1:0a83519 )
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/hibernate-issues/attachments/20200423/32289ec2/attachment.html 


More information about the hibernate-issues mailing list