I have an existing entity design. There is an Individual
entity. A Guardian
or a Minor
are stored as Individual
. If u r a Minor
, u r assigned zero or more guardians. This relationship is stored in a different entity.
There is an additional requirement; to add a flag to show that Guardian
Address
should be used for the Minor
if the relationship is set. One can clear that flag at a later time. If the flag is cleared, the existing address will be used and no changes to guardian's address will overwrite the minor's address.
The relationship between Minor
and Guardian
is stored as
(minor_individual_id, guardian_individual_id, type_of_the_relationship)
where type_of_the_relationship can have values such "legal" etc..
Is it as simple as adding a new flag to the relationship table ? Once added, the minor's address needs to be changed to the guardian's address. The address information is stored in another entity (Address
). Can this be done via Hibernate built-in functionality ? Or should we add a layer to take care of this functionality ? Is there anything in Hibernate that lets me know the flag has been updated and a new set of updates need to happen ?
The address entity contains the individual id and the address for the individual in a single table.
Once the flag is set, it can only be set once per minor since it will cause confusion to have minor having multiple guardians to have address cascade to be turned on for each of its guardians. Thanks.
Database Structure:
Individual ( Table/Entity)
Id
Age ( Depending on Age, you are treated as minor )
GuardianRelationShip ( Table/Entity)
Minor_Individual_Id
Guardian_Individual_Id
Address (Table/Entity)
Individual_Id
AddressLine1
City
State
If u r a Minor
with Individual
id of 2 and a have a Guardian
with Individual
id of 1. This will look like
Id Age (Individual)
1 40 Guardian
2 5 Minor
Minor Guardian (GuardianRelationShip)
2 1
IndividualId City State (Address)
1 LA CA
2 NY NY
Once those are linked, the idea is that the address for the minor "individual id of 2" will be changed to NY/NY.
If there is a req. that says use guardian address for minor and allow for unlinking address, how would you do that ?