Could somebody explain me how to map a one-to-zero association with hibernate (using mapping xml files NOT annotations)?
These are the rules:
- A Menu can have 0 or 1 Area associated.
- An Area belongs to a Menu. (Or, if it is easier for you to modelize it: An Area can have 0 or 1 Menu associated).
Here are the desired TABLES (I want to use foreign keys):
TABLE MENU:
ID
NAME
FKID_AREA
TABLE AREA:
ID
NAME
FKID_MENU
Thanks!
You should remove the
FKID_AREAfrom theMENUtable, because it’s not needed (and is even a problem, since it’s redendant withAREA.FKID_MENU).For the rest, this is described in the Hibernate documentation on bidirectional one-to-one association mappings: