I am working with some old hibernate code, and need to update and create a one to one.
I have a table
Table_1
PK table_1_id
FK table_2_id
Table_2
PK table_2_id
How do I map these in hibernate XML files so that the relationship is unqiue.. I have tried the
<many to one ... unique='true'>
but that does not work as it allows two records from table_1 to reference one row from table_2
This is the proper way, as documented in the documentation.
Hibernate will never prevent two records from
table_1to reference one the same row fromtable_2. That’s the role of the unique constraint that you should add on thetable_2_idcolumn oftable_1, in the database.