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. |