I'm new to hibernate and trying to evaluate if I can actually use it for my project. One type of entity needs to do some special checks on insert or update. I'm going to try to explain as easy as possible. 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.
How can i do this with hibernate?