FIX: When saving multiple m2m beans, only last m2m wins (Regression due #1630) (#1638)

* provide test case, that shows problem on multiple-m2m

* FIX: When saving multiple m2m beans, only last m2m wins (Regression due #1630)
This commit is contained in:
Roland Praml
2019-02-12 09:31:04 +13:00
committed by Rob Bygrave
parent 7929d8c0b8
commit fc7fae35c9
5 changed files with 67 additions and 6 deletions
@@ -187,7 +187,7 @@ public final class PersistRequestBean<T> extends PersistRequest implements BeanP
/**
* Many to many intersection table changes that are held for later batch processing.
*/
private SaveManyBeans saveManyIntersection;
private List<SaveManyBeans> saveManyIntersections;
public PersistRequestBean(SpiEbeanServer server, T bean, Object parentBean, BeanManager<T> mgr, SpiTransaction t,
PersistExecute persistExecute, PersistRequest.Type type, int flags) {
@@ -965,8 +965,8 @@ public final class PersistRequestBean<T> extends PersistRequest implements BeanP
}
private void saveQueuedManyIntersection() {
if (saveManyIntersection != null) {
saveManyIntersection.saveIntersectionBatch();
if (saveManyIntersections != null) {
saveManyIntersections.forEach(SaveManyBeans::saveIntersectionBatch);
}
}
@@ -1479,7 +1479,10 @@ public final class PersistRequestBean<T> extends PersistRequest implements BeanP
/**
* The intersection table updates to the batch executed later on postExecute.
*/
public void setManyIntersection(SaveManyBeans saveManyIntersection) {
this.saveManyIntersection = saveManyIntersection;
public void addManyIntersection(SaveManyBeans saveManyIntersection) {
if (this.saveManyIntersections == null) {
this.saveManyIntersections = new ArrayList<>();
}
this.saveManyIntersections.add(saveManyIntersection);
}
}
@@ -247,7 +247,7 @@ public class SaveManyBeans extends SaveManyBase {
if (request.isQueueManyIntersection()) {
// queue/delay until bean persist request is flushed
this.deleteMissing = deleteMissingChildren;
request.setManyIntersection(this);
request.addManyIntersection(this);
} else {
saveAssocManyIntersection(deleteMissingChildren, false);
}