mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
FIX: insert in batch OneToOne relationship (#1609)
This commit is contained in:
committed by
Rob Bygrave
parent
2e0690efa9
commit
bac53a5d75
@@ -0,0 +1,40 @@
|
||||
package org.tests.batchinsert;
|
||||
|
||||
import io.ebean.Ebean;
|
||||
import io.ebean.annotation.PersistBatch;
|
||||
import io.ebean.annotation.Transactional;
|
||||
import org.junit.Test;
|
||||
import org.tests.batchinsert.o2o.MeterAddressData;
|
||||
import org.tests.batchinsert.o2o.MeterContractData;
|
||||
import org.tests.batchinsert.o2o.MeterSpecialNeedsClient;
|
||||
import org.tests.batchinsert.o2o.MeterSpecialNeedsContact;
|
||||
import org.tests.batchinsert.o2o.MeterVersion;
|
||||
|
||||
public class TestBatchInsertOneToOne {
|
||||
private MeterVersion build(){
|
||||
MeterAddressData addressData = new MeterAddressData();
|
||||
addressData.setStreet("street");
|
||||
MeterContractData contractData = new MeterContractData();
|
||||
|
||||
MeterSpecialNeedsClient specialNeedsClient = new MeterSpecialNeedsClient();
|
||||
contractData.setSpecialNeedsClient(specialNeedsClient);
|
||||
|
||||
MeterSpecialNeedsContact contact1 = new MeterSpecialNeedsContact();
|
||||
|
||||
specialNeedsClient.setPrimary(contact1);
|
||||
|
||||
MeterVersion meterVersion = new MeterVersion();
|
||||
meterVersion.setAddressData(addressData);
|
||||
meterVersion.setContractData(contractData);
|
||||
|
||||
return meterVersion;
|
||||
}
|
||||
|
||||
@Transactional(batch = PersistBatch.ALL, batchOnCascade = PersistBatch.ALL, batchSize = 10)
|
||||
@Test
|
||||
public void test() {
|
||||
MeterVersion meterVersion = build();
|
||||
|
||||
Ebean.save(meterVersion);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package org.tests.batchinsert.o2o;
|
||||
|
||||
import io.ebean.annotation.NotNull;
|
||||
import java.util.UUID;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
|
||||
@Entity
|
||||
public class MeterAddressData {
|
||||
@Id
|
||||
private UUID id;
|
||||
|
||||
@NotNull
|
||||
private String street;
|
||||
|
||||
public String getStreet() {
|
||||
return street;
|
||||
}
|
||||
|
||||
public void setStreet(String street) {
|
||||
this.street = street;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package org.tests.batchinsert.o2o;
|
||||
|
||||
import io.ebean.annotation.NotNull;
|
||||
import java.util.UUID;
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.OneToOne;
|
||||
|
||||
@Entity
|
||||
public class MeterContractData {
|
||||
@Id
|
||||
private UUID id;
|
||||
|
||||
@NotNull
|
||||
@OneToOne(cascade = CascadeType.ALL)
|
||||
private MeterSpecialNeedsClient specialNeedsClient;
|
||||
|
||||
public MeterSpecialNeedsClient getSpecialNeedsClient() {
|
||||
return specialNeedsClient;
|
||||
}
|
||||
|
||||
public void setSpecialNeedsClient(MeterSpecialNeedsClient specialNeedsClient) {
|
||||
this.specialNeedsClient = specialNeedsClient;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package org.tests.batchinsert.o2o;
|
||||
|
||||
import java.util.UUID;
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.OneToOne;
|
||||
|
||||
@Entity
|
||||
public class MeterSpecialNeedsClient {
|
||||
@Id
|
||||
private UUID id;
|
||||
|
||||
private String name;
|
||||
|
||||
@OneToOne(cascade = CascadeType.ALL)
|
||||
private MeterSpecialNeedsContact primary;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public MeterSpecialNeedsContact getPrimary() {
|
||||
return primary;
|
||||
}
|
||||
|
||||
public void setPrimary(MeterSpecialNeedsContact primary) {
|
||||
this.primary = primary;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package org.tests.batchinsert.o2o;
|
||||
|
||||
import java.util.UUID;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
|
||||
@Entity
|
||||
public class MeterSpecialNeedsContact {
|
||||
@Id
|
||||
private UUID id;
|
||||
|
||||
private String name;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package org.tests.batchinsert.o2o;
|
||||
|
||||
import io.ebean.annotation.NotNull;
|
||||
import java.util.UUID;
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.OneToOne;
|
||||
|
||||
@Entity
|
||||
public class MeterVersion {
|
||||
@Id
|
||||
private UUID id;
|
||||
|
||||
//@NotNull
|
||||
@OneToOne(cascade = CascadeType.ALL)
|
||||
private MeterAddressData addressData;
|
||||
|
||||
@NotNull
|
||||
@OneToOne(cascade = CascadeType.ALL)
|
||||
private MeterContractData contractData;
|
||||
|
||||
public MeterAddressData getAddressData() {
|
||||
return addressData;
|
||||
}
|
||||
|
||||
public void setAddressData(MeterAddressData addressData) {
|
||||
this.addressData = addressData;
|
||||
}
|
||||
|
||||
public MeterContractData getContractData() {
|
||||
return contractData;
|
||||
}
|
||||
|
||||
public void setContractData(MeterContractData contractData) {
|
||||
this.contractData = contractData;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user