mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#1826 - Remove PrivateOwned, migrate to orphanRemoval=true attribute on OneToMany
This commit is contained in:
@@ -1,58 +0,0 @@
|
||||
package org.tests.cascade;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.Ebean;
|
||||
import io.ebean.annotation.IgnorePlatform;
|
||||
import io.ebean.annotation.Platform;
|
||||
import io.ebean.bean.BeanCollection;
|
||||
import org.tests.model.basic.TSDetailTwo;
|
||||
import org.tests.model.basic.TSMasterTwo;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class TestPrivateOwnedNoCascadeRemove extends BaseTestCase {
|
||||
|
||||
@IgnorePlatform(Platform.NUODB)
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
TSMasterTwo m0 = new TSMasterTwo();
|
||||
m0.setName("m1");
|
||||
|
||||
m0.addDetail(new TSDetailTwo("m1 detail 1"));
|
||||
m0.addDetail(new TSDetailTwo("m1 detail 2"));
|
||||
|
||||
Ebean.save(m0);
|
||||
|
||||
TSMasterTwo master = Ebean.find(TSMasterTwo.class, m0.getId());
|
||||
List<TSDetailTwo> details = master.getDetails();
|
||||
|
||||
TSDetailTwo removedDetail = details.remove(1);
|
||||
|
||||
BeanCollection<?> bc = (BeanCollection<?>) details;
|
||||
Set<?> modifyRemovals = bc.getModifyRemovals();
|
||||
|
||||
Assert.assertNotNull(modifyRemovals);
|
||||
Assert.assertTrue(modifyRemovals.size() == 1);
|
||||
Assert.assertTrue(modifyRemovals.contains(removedDetail));
|
||||
|
||||
Ebean.save(master);
|
||||
|
||||
TSMasterTwo masterReload = Ebean.find(TSMasterTwo.class, m0.getId());
|
||||
List<TSDetailTwo> detailsReload = masterReload.getDetails();
|
||||
|
||||
// the removed bean has really been removed
|
||||
Assert.assertTrue(detailsReload.size() == 1);
|
||||
|
||||
try {
|
||||
Ebean.delete(masterReload);
|
||||
Assert.fail("delete should error");
|
||||
} catch (Exception e) {
|
||||
Assert.assertTrue("delete failed", true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,13 +1,12 @@
|
||||
package org.tests.inheritance;
|
||||
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.OneToOne;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
import io.ebean.annotation.PrivateOwned;
|
||||
import static javax.persistence.CascadeType.ALL;
|
||||
import static javax.persistence.FetchType.LAZY;
|
||||
|
||||
/**
|
||||
* Model class to reference an organization tree node.
|
||||
@@ -22,9 +21,8 @@ public class OrganizationTreeNode {
|
||||
|
||||
private String name;
|
||||
|
||||
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "parentTreeNode")
|
||||
@OneToOne(cascade = ALL, fetch = LAZY, mappedBy = "parentTreeNode", orphanRemoval = true)
|
||||
@NotNull
|
||||
@PrivateOwned
|
||||
private OrganizationNode organizationNode;
|
||||
|
||||
public Long getId() {
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
package org.tests.model.basic;
|
||||
|
||||
import io.ebean.annotation.PrivateOwned;
|
||||
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.Version;
|
||||
import java.util.List;
|
||||
|
||||
import static javax.persistence.CascadeType.PERSIST;
|
||||
|
||||
@Entity
|
||||
public class AnimalShelter {
|
||||
|
||||
@@ -20,8 +19,7 @@ public class AnimalShelter {
|
||||
|
||||
String name;
|
||||
|
||||
@OneToMany(cascade = CascadeType.PERSIST, mappedBy = "shelter")
|
||||
@PrivateOwned
|
||||
@OneToMany(cascade = PERSIST, mappedBy = "shelter", orphanRemoval = true)
|
||||
List<Animal> animals;
|
||||
|
||||
public Long getId() {
|
||||
|
||||
@@ -1,14 +1,11 @@
|
||||
package org.tests.model.basic;
|
||||
|
||||
import io.ebean.annotation.UpdateMode;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
@Entity
|
||||
@Table(name = "t_mapsuper1")
|
||||
@UpdateMode(updateChangesOnly = true)
|
||||
public class TMapSuperEntity extends TMappedSuper2 {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -1,74 +0,0 @@
|
||||
package org.tests.model.basic;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.Table;
|
||||
|
||||
/**
|
||||
* A basic entity to test simple things.
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "ts_detail_two")
|
||||
public class TSDetailTwo {
|
||||
|
||||
@Id
|
||||
Integer id;
|
||||
|
||||
String name;
|
||||
|
||||
String description;
|
||||
|
||||
boolean active;
|
||||
|
||||
@ManyToOne
|
||||
TSMasterTwo master;
|
||||
|
||||
public TSDetailTwo(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public TSDetailTwo() {
|
||||
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public boolean isActive() {
|
||||
return active;
|
||||
}
|
||||
|
||||
public void setActive(boolean active) {
|
||||
this.active = active;
|
||||
}
|
||||
|
||||
public TSMasterTwo getMaster() {
|
||||
return master;
|
||||
}
|
||||
|
||||
public void setMaster(TSMasterTwo master) {
|
||||
this.master = master;
|
||||
}
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
package org.tests.model.basic;
|
||||
|
||||
import io.ebean.annotation.PrivateOwned;
|
||||
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.Table;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A basic entity to test simple things.
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "ts_master_two")
|
||||
public class TSMasterTwo {
|
||||
|
||||
@Id
|
||||
Integer id;
|
||||
|
||||
String name;
|
||||
|
||||
String description;
|
||||
|
||||
boolean active;
|
||||
|
||||
@OneToMany(cascade = CascadeType.ALL, mappedBy = "master")
|
||||
@PrivateOwned(cascadeRemove = false)
|
||||
List<TSDetailTwo> details;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public boolean isActive() {
|
||||
return active;
|
||||
}
|
||||
|
||||
public void setActive(boolean active) {
|
||||
this.active = active;
|
||||
}
|
||||
|
||||
public List<TSDetailTwo> getDetails() {
|
||||
return details;
|
||||
}
|
||||
|
||||
public void setDetails(List<TSDetailTwo> details) {
|
||||
this.details = details;
|
||||
}
|
||||
|
||||
public void addDetail(TSDetailTwo detail) {
|
||||
if (details == null) {
|
||||
details = new ArrayList<>();
|
||||
}
|
||||
details.add(detail);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
package org.tests.model.embedded;
|
||||
|
||||
import io.ebean.annotation.PrivateOwned;
|
||||
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Embedded;
|
||||
import javax.persistence.Entity;
|
||||
@@ -20,8 +18,7 @@ public class EEmbOuter {
|
||||
@Version
|
||||
private int updateCount;
|
||||
|
||||
@OneToMany(cascade = CascadeType.ALL)
|
||||
@PrivateOwned
|
||||
@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
|
||||
List<EEmbInner> inners;
|
||||
|
||||
@Embedded
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package org.tests.model.selfref;
|
||||
|
||||
import io.ebean.annotation.PrivateOwned;
|
||||
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
@@ -23,8 +21,7 @@ public class ResourceFile extends BaseResourceFile {
|
||||
@JoinColumn(name = "parentresourcefileid", nullable = true)
|
||||
private ResourceFile parent;
|
||||
|
||||
@OneToMany(cascade = CascadeType.REMOVE, fetch = FetchType.LAZY, mappedBy = "parent")
|
||||
@PrivateOwned
|
||||
@OneToMany(cascade = CascadeType.REMOVE, fetch = FetchType.LAZY, mappedBy = "parent", orphanRemoval = true)
|
||||
private Set<ResourceFile> alternatives = new HashSet<>();
|
||||
|
||||
@Column(name = "name", length = 128, nullable = false)
|
||||
|
||||
Reference in New Issue
Block a user