I'm new both to spring and hibernate so take that into consideration in your answer.
I have a many-to-many relationship were the link-table must also contain information. I will try to solve this according to:
How Do I Create Many to Many Hibernate Mapping for Additional Property from the Join Table?
My Question is related to:
hibernate: Custom code on insert / update
But I just repeat it here so no clicking on link is required:
Lets say we have colors. A user can create a Mixture of n colors and store that mixture in the database. Later if a user searches for color "blue" all Mixtures containing blue should be displayed.
Business rule is that any color should only be in the database once. So if a new mixture is inserted, it must first be checked if all the colors are already in the database and if yes that color should be reused (referenced) and if not a new one should be created.
If a mixture is changed say "blue" is replaced with "red", the behavior must be that the initial "blue" remains untouched and the system checks if "red" exists and either reuses it or creates it and then adds it to the mixture.
The important part is that "Colors" are managed by the system and an existing color must never change."red" will always be "red" and should never be changed to "blue". Since I'm new to Hibernate and Spring I'm kind of lost on how to implement this rule and at what level.IMHO I would put that logic at the lowest level possible so that it doesn't break if you (the developer) forgets to check it. does that make sense? Better ideas or suggestions?