recalc lazyload duplicate key (#53)

This commit is contained in:
maTrojak
2021-12-15 08:13:16 +01:00
committed by GitHub
parent 21d4ee2fb6
commit fa2c5c0584
4 changed files with 145 additions and 6 deletions
@@ -147,10 +147,13 @@ public final class PersistRequestBean<T> extends PersistRequest implements BeanP
PersistExecute persistExecute, PersistRequest.Type type, int flags) {
super(server, t, persistExecute);
this.entityBean = (EntityBean) bean;
this.entityBean._ebean_onPersistTrigger(type.profileEventId);
this.intercept = entityBean._ebean_getIntercept();
this.beanManager = mgr;
this.beanDescriptor = mgr.getBeanDescriptor();
boolean isReference = beanDescriptor.isReference(intercept);
if(!isReference) {
this.entityBean._ebean_onPersistTrigger(type.profileEventId);
}
this.beanManager = mgr;
this.beanPersistListener = beanDescriptor.persistListener();
this.bean = bean;
this.parentBean = parentBean;
@@ -0,0 +1,44 @@
package org.tests.o2o;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.OneToOne;
@Entity
public class OtoLevelALazy {
@Id
private Long id;
private String name;
@OneToOne(mappedBy = "a", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY)
private OtoLevelBLazy b;
public OtoLevelALazy(String name) {
this.name = name;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public OtoLevelBLazy getB() {
return b;
}
public void setB(OtoLevelBLazy b) {
this.b = b;
}
public void setName(String name) {
this.name = name;
}
}
@@ -0,0 +1,76 @@
package org.tests.o2o;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.ManyToMany;
import javax.persistence.OneToOne;
@Entity
public class OtoLevelBLazy {
@Id
private Long id;
private String name;
@ManyToMany()
private List<OtoLevelC> c;
@OneToOne()
private OtoLevelALazy a;
@Lob
private String blob;
public OtoLevelBLazy(String name) {
this.name = name;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public OtoLevelALazy getA() {
return a;
}
public void setA(OtoLevelALazy a) {
this.a = a;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public List<OtoLevelC> getC() {
return c;
}
public final void _ebean_onPersistTrigger(String trt) {
recalc();
}
protected void recalc() {
this.getBlob();
}
public String getBlob() {
return blob;
}
public void setBlob(String blob) {
this.blob = blob;
}
}
@@ -1,13 +1,14 @@
package org.tests.o2o;
import io.ebean.DB;
import io.ebean.test.LoggedSql;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.jupiter.api.Test;
import io.ebean.DB;
import io.ebean.test.LoggedSql;
public class TestOneToOneSaveWithoutChanges {
@@ -33,4 +34,19 @@ public class TestOneToOneSaveWithoutChanges {
List<String> sql = LoggedSql.stop();
assertThat(sql).hasSize(0);
}
@Test
public void testSave2LevelsLazyPersistTrigger() {
OtoLevelALazy a = new OtoLevelALazy("A");
OtoLevelBLazy b = new OtoLevelBLazy("B");
b.setA(a);
DB.save(a);
DB.save(b);
OtoLevelALazy dbA = DB.find(OtoLevelALazy.class).select("*").where().idEq(1).findList().get(0);
LoggedSql.start();
DB.save(dbA);
List<String> sql = LoggedSql.stop();
assertThat(sql).hasSize(0);
}
}