mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-11 06:30:28 +00:00
#1832 - Cascade insert @ElementCollection when marshalled from JSON
This commit is contained in:
1 parent
7a6662a2dc
commit
1098b572fe
4 files changed
+110
-33
No files matched your search
@@ -0,0 +1,41 @@
|
||||
package org.tests.model.elementcollection;
|
||||
|
||||
|
||||
import io.ebean.DB;
|
||||
import io.ebean.text.json.JsonContext;
|
||||
import org.ebeantest.LoggedSqlCollector;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class EcmPersonTest {
|
||||
|
||||
@Test
|
||||
public void readJsonThenInsert() {
|
||||
|
||||
EcmPerson source = new EcmPerson("Ethan027");
|
||||
source.getPhoneNumbers().put("home", "027 1234");
|
||||
source.getPhoneNumbers().put("work", "027 4321");
|
||||
|
||||
final JsonContext json = DB.json();
|
||||
final String asJson = json.toJson(source);
|
||||
|
||||
final EcmPerson person = json.toBean(EcmPerson.class, asJson);
|
||||
|
||||
LoggedSqlCollector.start();
|
||||
|
||||
DB.save(person);
|
||||
|
||||
final List<String> sql = LoggedSqlCollector.stop();
|
||||
|
||||
assertThat(sql).hasSize(4);
|
||||
assertThat(sql.get(0)).contains("insert into ecm_person ");
|
||||
assertThat(sql.get(1)).contains("insert into ecm_person_phone_numbers ");
|
||||
assertThat(sql.get(2)).contains("-- bind");
|
||||
assertThat(sql.get(3)).contains("-- bind");
|
||||
|
||||
DB.delete(person);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package org.tests.model.elementcollection;
|
||||
|
||||
import io.ebean.DB;
|
||||
import io.ebean.text.json.JsonContext;
|
||||
import org.ebeantest.LoggedSqlCollector;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class EcsPersonTest {
|
||||
|
||||
@Test
|
||||
public void jsonReadThenInsert() {
|
||||
|
||||
EcsPerson source = new EcsPerson("Ethan027");
|
||||
source.getPhoneNumbers().add("027 1234");
|
||||
source.getPhoneNumbers().add("027 4321");
|
||||
|
||||
final JsonContext json = DB.json();
|
||||
final String asJson = json.toJson(source);
|
||||
|
||||
final EcsPerson person = json.toBean(EcsPerson.class, asJson);
|
||||
|
||||
LoggedSqlCollector.start();
|
||||
|
||||
DB.save(person);
|
||||
|
||||
final List<String> sql = LoggedSqlCollector.stop();
|
||||
|
||||
assertThat(sql).hasSize(4);
|
||||
assertThat(sql.get(0)).contains("insert into ecs_person ");
|
||||
assertThat(sql.get(1)).contains("insert into ecs_person_phone ");
|
||||
assertThat(sql.get(2)).contains("-- bind");
|
||||
assertThat(sql.get(3)).contains("-- bind");
|
||||
|
||||
DB.delete(person);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user