It will ease life for newcomers, as the “flush()” invokation is needed for DataNucleus to update “mappedBy” collections, for example, when a new element has been added.
For Queries, we’re currently invoking always flush(…) before executing it on the persistence layer, but that’s not the default behavior when setting a property, for example.
So when DN reloads entities collections would not be updated.
Let's see an example (notice the "this.persistAndFlush(...)" helper method invocation):
public abstract class Warehouse extends SalesVIPEntity<Marketplace> {
// {{ ExcludedProducts (Collection)
@Persistent(mappedBy = "marketplace", dependentElement = "true")
private SortedSet<MarketplaceExcludedProduct> excludedProducts = new TreeSet<MarketplaceExcludedProduct>();
@MemberOrder(sequence = "1")
public SortedSet<MarketplaceExcludedProduct> getExcludedProducts()
public void setExcludedProducts(
final SortedSet<MarketplaceExcludedProduct> excludedProducts)
// }}
// {{ addExcludedProduct (action)
@Action(semantics = SemanticsOf.IDEMPOTENT)
@MemberOrder(sequence = "1")
public MarketplaceExcludedProduct addExcludedProduct(final Product product) {
MarketplaceExcludedProduct marketplaceExcludedProduct = this
.findExcludedProduct(product);
if (marketplaceExcludedProduct == null)
this.wrap(marketplaceExcludedProduct).setMarketplace(this);
this.wrap(marketplaceExcludedProduct).setProduct(product);
this.persistAndFlush(marketplaceExcludedProduct); <—————————————
return marketplaceExcludedProduct;
}
// }}
// {{ deleteFromExcludedProducts (action)
@Action(semantics = SemanticsOf.IDEMPOTENT)
@MemberOrder(sequence = "1")
public void deleteFromExcludedProducts(final Product product) {
final MarketplaceExcludedProduct marketplaceExcludedProduct = this
.findExcludedProduct(product);
if (marketplaceExcludedProduct != null)
}
// }}
// {{ findExcludedProduct (action)
@Action(semantics = SemanticsOf.SAFE)
@MemberOrder(sequence = "1")
public MarketplaceExcludedProduct findExcludedProduct(final Product product)
// }}
// {{ findAllProductsExcluded (action)
@Action(semantics = SemanticsOf.SAFE, hidden = Where.EVERYWHERE)
public Set<Product> findAllProductsExcluded()
// }}
}
On the “addExcludedProduct()” action, if the user don’t flush(), in addition to persist(), this test would fail, not containing the given product:
@Test
public void addExcludedProduct()