w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Hibernate annotation @OnetoOne doesn't seem to restrict many to one entries in the database

Hibernate won't check is another person already points to the same person details. Even if it did, the situation might change right after (since transactions execute concurrently), and such a check would thus not be effective. That's why this check must be done by the database itself, using a unique constraint on the Person.personDetailsFK column.

AFAIK, Hibernate generates such a unique constraint if you ask it to generate the database schema for you. If you don't, then make sure to create such a constraint.





© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.