Gavin King (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
) *created* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiNDc4YWJlMDg3...
) / Bug (
https://hibernate.atlassian.net/browse/HHH-15767?atlOrigin=eyJpIjoiNDc4YW...
) HHH-15767 (
https://hibernate.atlassian.net/browse/HHH-15767?atlOrigin=eyJpIjoiNDc4YW...
) missing unique constraints from optional @OneToOne (
https://hibernate.atlassian.net/browse/HHH-15767?atlOrigin=eyJpIjoiNDc4YW...
)
Issue Type: Bug Assignee: Unassigned Components: hibernate-core Created: 26/Nov/2022 07:00
AM Priority: Major Reporter: Gavin King (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
)
Currently Hibernate never automatically produces unique constraints on foreign key columns
mapped using @OneToOne unless the association is explicitly marked optional=false. There
are two a comments in the source code to the effect that this is intentional because “some
databases like Derby” don’t support that. Well, as of 2022, Derby does seem to support
that, and even if it didn’t, having the limitations of Derby of all things constrain what
we do on real databases seems just … completely wrong.
(Damn, feels like we need some sort of thing that abstracts over the differences between
SQL dialects. Really wish we had a thing like that…)
Now, the problem is that, without the unique constraint, there is simply no difference at
all between @OneToOne and @ManyToOne and so you can use @OneToOne as a bad @ManyToOne and,
well, apparently people do, because fixing this broke multiple badly-written tests!
So look, there’s simply no excuse for not fixing this. Yes, I understand that in principle
some people’s programs will break. (This will really only affect tests, since that is, we
hope, where schema export is mostly used.) The current situation is untenable.
(
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 )