mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#1487 - @OneToOne Postgres with different Id types - error PSQLException: ERROR: operator does not exist: uuid = character varying
Test
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
package org.tests.model.uuidsibling;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.hamcrest.core.Is.is;
|
||||
import static org.hamcrest.core.IsNot.not;
|
||||
import static org.hamcrest.core.IsNull.nullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
public class SoftDeleteCascadeTest {
|
||||
|
||||
@Test
|
||||
public void testDeleteParent() {
|
||||
// Insert + link records
|
||||
USibParent parent = new USibParent();
|
||||
parent.save();
|
||||
|
||||
USibChild child = new USibChild(parent);
|
||||
child.save();
|
||||
|
||||
USibChildSibling childSibling = new USibChildSibling(child);
|
||||
childSibling.save();
|
||||
|
||||
Long parentId = parent.getId();
|
||||
UUID childId = child.getId();
|
||||
Long childSiblingId = childSibling.getId();
|
||||
|
||||
assertBefore(parent, child, childSibling);
|
||||
parent.delete();
|
||||
assertAfter(parentId, childId, childSiblingId);
|
||||
}
|
||||
|
||||
private void assertBefore(USibParent parent, USibChild child, USibChildSibling childSibling) {
|
||||
|
||||
parent.refresh();
|
||||
|
||||
assertThat("Parent should have one child loaded",
|
||||
parent.getChildren().size(),
|
||||
is(1)
|
||||
);
|
||||
|
||||
assertThat("Parent should have correct child loaded",
|
||||
parent.getChildren().get(0).getId(),
|
||||
is(child.getId())
|
||||
);
|
||||
|
||||
assertThat("Child that was loaded should have its sibling available",
|
||||
parent.getChildren().get(0).getChildSibling(),
|
||||
not(nullValue())
|
||||
);
|
||||
|
||||
assertThat(
|
||||
"Child that was loaded should have loaded correct sibling",
|
||||
parent.getChildren().get(0).getChildSibling().getId(),
|
||||
is(childSibling.getId())
|
||||
);
|
||||
}
|
||||
|
||||
private void assertAfter(Long parentId, UUID childId, Long childSiblingId) {
|
||||
assertThat(USibParent.find.byId(parentId), is(nullValue()));
|
||||
assertThat(USibChild.find.byId(childId), is(nullValue()));
|
||||
assertThat(USibChildSibling.find.byId(childSiblingId), is(nullValue()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package org.tests.model.uuidsibling;
|
||||
|
||||
import io.ebean.Finder;
|
||||
import io.ebean.Model;
|
||||
import io.ebean.annotation.SoftDelete;
|
||||
import java.util.UUID;
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.OneToOne;
|
||||
|
||||
@Entity
|
||||
public class USibChild extends Model {
|
||||
|
||||
private static final long serialVersionUID = 738194912181571389L;
|
||||
|
||||
@Id
|
||||
private UUID id;
|
||||
|
||||
@SoftDelete
|
||||
private boolean deleted;
|
||||
|
||||
@OneToOne(mappedBy = "child", cascade = CascadeType.REMOVE)
|
||||
private USibChildSibling childSibling;
|
||||
|
||||
@ManyToOne
|
||||
private USibParent parent;
|
||||
|
||||
public static Finder<UUID, USibChild> find = new Finder<>(USibChild.class);
|
||||
|
||||
public USibChild() {}
|
||||
|
||||
public USibChild(USibParent parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(UUID id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public boolean isDeleted() {
|
||||
return deleted;
|
||||
}
|
||||
|
||||
public void setDeleted(boolean deleted) {
|
||||
this.deleted = deleted;
|
||||
}
|
||||
|
||||
public USibChildSibling getChildSibling() {
|
||||
return childSibling;
|
||||
}
|
||||
|
||||
public USibChild setChildSibling(USibChildSibling childSibling) {
|
||||
this.childSibling = childSibling;
|
||||
return this;
|
||||
}
|
||||
|
||||
public USibParent getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
public void setParent(USibParent parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package org.tests.model.uuidsibling;
|
||||
|
||||
import io.ebean.Finder;
|
||||
import io.ebean.Model;
|
||||
import io.ebean.annotation.SoftDelete;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.OneToOne;
|
||||
|
||||
@Entity
|
||||
public class USibChildSibling extends Model {
|
||||
|
||||
private static final long serialVersionUID = 738194912181571389L;
|
||||
|
||||
@Id
|
||||
private Long id;
|
||||
|
||||
@SoftDelete
|
||||
private boolean deleted;
|
||||
|
||||
@OneToOne
|
||||
private USibChild child;
|
||||
|
||||
public static Finder<Long, USibChildSibling> find = new Finder<>(USibChildSibling.class);
|
||||
|
||||
public USibChildSibling() {}
|
||||
|
||||
public USibChildSibling(USibChild child) {
|
||||
this.child = child;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public boolean isDeleted() {
|
||||
return deleted;
|
||||
}
|
||||
|
||||
public void setDeleted(boolean deleted) {
|
||||
this.deleted = deleted;
|
||||
}
|
||||
|
||||
public USibChild getChild() {
|
||||
return child;
|
||||
}
|
||||
|
||||
public USibChildSibling setChild(USibChild child) {
|
||||
this.child = child;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package org.tests.model.uuidsibling;
|
||||
|
||||
import io.ebean.Finder;
|
||||
import io.ebean.Model;
|
||||
import io.ebean.annotation.SoftDelete;
|
||||
import java.util.List;
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.OneToMany;
|
||||
|
||||
@Entity
|
||||
public class USibParent extends Model {
|
||||
|
||||
private static final long serialVersionUID = 4116545858939406149L;
|
||||
|
||||
@Id
|
||||
private Long id;
|
||||
|
||||
@SoftDelete
|
||||
private boolean deleted;
|
||||
|
||||
@OneToMany(cascade = CascadeType.REMOVE, mappedBy = "parent")
|
||||
private List<USibChild> children;
|
||||
|
||||
public static Finder<Long, USibParent> find = new Finder<>(USibParent.class);
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public boolean isDeleted() {
|
||||
return deleted;
|
||||
}
|
||||
|
||||
public void setDeleted(boolean deleted) {
|
||||
this.deleted = deleted;
|
||||
}
|
||||
|
||||
public List<USibChild> getChildren() {
|
||||
return children;
|
||||
}
|
||||
|
||||
public USibParent setChildren(List<USibChild> children) {
|
||||
this.children = children;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user