on 2018 Apr 08 5:04 PM
Hi Experts,
Is there a good way to save a model without causing the implicit saving of referred models?
For instance, a PriceRowModel contains a product attribute that is a reference to a ProductModel.
Due to that, in the following code example (very simplified) the product is implicitly being saved when I save the product row:
public void updateProduct(String code, ProductChangesBean changes) {
ProductModel product = productService.getProductForCode(catVersion, code);
// ...do some changes to the product...
updateProductUnit(product, changes.getUnitC());
// ...do more changes to the product...
modelService.save(product);
}
public void updateProductUnit(ProductModel product, UnitModel unit)
if (unit == null) {
return;
}
product.setUnit(unit);
for (PriceRowModel priceRow : product.getEurope1Prices()) {
priceRow.setUnit(unit);
modelService.save(priceRow); // <== this is saving priceRow's and product
}
}
I would like updateProductUnit(..) to save only the price rows without saving the product referred by them.
I have tried detaching the product before saving the price row, but the product is still being saved with it.
I also tried with not saving the price row, to see if the saving of the product will "cascade" that. But it doesn't.
Any other ideas?
Cheers,
Carlos
Request clarification before answering.
| User | Count |
|---|---|
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.