I am having a problem with JPA that I can't understand why. Here's the scenario.
I have my entity called RecipeVersion, that has a composite Id, that is composed by
recipeVersionId | recipeId | storeId
There is a business rule, that whenever a recipe version is already associated with a product, it cannot be altered, if the user tries to alter that version, a new version is persisted with his alterations, leaving the original one unchanged.
so when I get on this specific case, I make a copy of the object, so I don't have any problem with the references and add 1 to the value of the version by code.
if the PK is:
recipeVersionId = 1
recipeId = 32
storeId = 1
I search the database for the highest version of that recipe, and add 1, so in this case, if there is only that 1 recipe, the new PK looks like this: