Gavin King (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
) *commented* on HHH-15767 (
https://hibernate.atlassian.net/browse/HHH-15767?atlOrigin=eyJpIjoiYWIzNm...
)
Re: missing unique constraints from optional @OneToOne (
https://hibernate.atlassian.net/browse/HHH-15767?atlOrigin=eyJpIjoiYWIzNm...
)
So I now sort of understand why this was like that. Essentially: we just didn’t have
consistent semantics for our unique constraints, since on Sybase, SQL Server, and DB2 the
traditional semantics was that null=null for deciding uniqueness. And that wasn’t what we
wanted for a @OneToOne with a FK.
Well, as of 2022, that’s been semi-fixed for a while in SQL Server and DB2. There is a way
to create a unique index where null<>null on SQL server and on all flavors of DB2.
For SQL server it is
create unique nonclustered index name on table (column) where column is not null
And on DB2 it is either:
create unique index name on table (column) exclude null keys
or, on i or Z series:
create unique where not null index name on table (column)
The only database where it’s still impossible is Sybase.
So my solution is, as kind of a second part of
https://hibernate.atlassian.net/browse/HHH-15762 (
https://hibernate.atlassian.net/browse/HHH-15762 ) , finally give our unique constraints
on nullable columns a consistent semantic, and just refuse to create them on Sybase.
(
https://hibernate.atlassian.net/browse/HHH-15767#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-15767#add-comment?atlOrigin=ey...
)
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....
) or iOS (
https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=Em...
) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100210- sha1:eab5823 )