Hello Forum,

I have a bidirectional 1:N relationship between two entities Formula and FormulaInputValue. Formula has therefore a member variable of type Set<FormulaInputValue> and a method addFormulaInputValue() which adds a new generated FormulaInputValue to the Set and creates the references. What is the best way to populate the id of the new FormulaInputValue entity?

I have an FormulaManager which has a method addFormulaInputValue that has the @Transactional annotation and that is called from the client.

Code:
       @Transactional
	public void addFormulaInputValue(String description, Double value, Long formulaId) {
		Formula formula = formulaRepository.getById(formulaId);
		formula.addFormulaInputValue(description, value);
	}
The following method of the Formula entity is called in the same transaction:

Code:
       public void addFormulaInputValue(String description, Double value) {
		FormulaInputValue inputValue = new FormulaInputValue(description, value);
		formulaInputValues.add(inputValue);
		inputValue.setFormula(this);
	}
When the addFormulaInputValue returns, the id of the new FormulaInputValue is still NULL. What is the best way of getting this object persisted and that I can use the id in the method of the FormulaManager?