mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
Add test demonstrating soft-delete bug with optional relationship
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
package org.tests.model.softdelete;
|
||||
|
||||
import io.ebean.annotation.SoftDelete;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.util.UUID;
|
||||
|
||||
@Entity
|
||||
public class ESoftDelX {
|
||||
|
||||
@Id
|
||||
private UUID id;
|
||||
|
||||
@OneToOne
|
||||
private ESoftDelY y;
|
||||
|
||||
@ManyToOne
|
||||
private ESoftDelZ organization;
|
||||
|
||||
@SoftDelete
|
||||
boolean deleted;
|
||||
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(UUID id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public ESoftDelY getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public void setY(ESoftDelY y) {
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public ESoftDelZ getOrganization() {
|
||||
return organization;
|
||||
}
|
||||
|
||||
public void setOrganization(ESoftDelZ organization) {
|
||||
this.organization = organization;
|
||||
}
|
||||
|
||||
public boolean isDeleted() {
|
||||
return deleted;
|
||||
}
|
||||
|
||||
public void setDeleted(boolean deleted) {
|
||||
this.deleted = deleted;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package org.tests.model.softdelete;
|
||||
|
||||
import io.ebean.annotation.SoftDelete;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
@Entity
|
||||
public class ESoftDelY {
|
||||
|
||||
@Id
|
||||
private Long id;
|
||||
|
||||
@ManyToOne
|
||||
private ESoftDelZ organization;
|
||||
|
||||
@OneToOne(mappedBy = "y")
|
||||
private ESoftDelX x;
|
||||
|
||||
@SoftDelete
|
||||
boolean deleted;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public ESoftDelZ getOrganization() {
|
||||
return organization;
|
||||
}
|
||||
|
||||
public void setOrganization(ESoftDelZ organization) {
|
||||
this.organization = organization;
|
||||
}
|
||||
|
||||
public ESoftDelX getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public void setX(ESoftDelX x) {
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
public boolean isDeleted() {
|
||||
return deleted;
|
||||
}
|
||||
|
||||
public void setDeleted(boolean deleted) {
|
||||
this.deleted = deleted;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package org.tests.model.softdelete;
|
||||
|
||||
import io.ebean.annotation.SoftDelete;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import java.util.UUID;
|
||||
|
||||
@Entity
|
||||
public class ESoftDelZ {
|
||||
|
||||
@Id
|
||||
private Long id;
|
||||
|
||||
@SoftDelete
|
||||
private boolean deleted;
|
||||
|
||||
private UUID uuid;
|
||||
|
||||
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 UUID getUuid() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
public void setUuid(UUID uuid) {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,15 @@
|
||||
package org.tests.softdelete;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.DB;
|
||||
import io.ebean.Ebean;
|
||||
import org.tests.model.softdelete.ESoftDelMid;
|
||||
import io.ebean.Finder;
|
||||
import org.junit.Test;
|
||||
import org.tests.model.softdelete.ESoftDelY;
|
||||
import org.tests.model.softdelete.ESoftDelZ;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -24,5 +30,30 @@ public class TestSoftDeleteOptionalRelationship extends BaseTestCase {
|
||||
assertThat(bean.getTop()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindNullWhenMultiple() {
|
||||
UUID uuid = UUID.randomUUID();
|
||||
{
|
||||
ESoftDelZ z = new ESoftDelZ();
|
||||
z.setUuid(uuid);
|
||||
DB.save(z);
|
||||
|
||||
ESoftDelY y = new ESoftDelY();
|
||||
y.setOrganization(z);
|
||||
y.setX(null);
|
||||
DB.save(y);
|
||||
}
|
||||
|
||||
Finder<Long, ESoftDelY> finder = new Finder<>(ESoftDelY.class);
|
||||
ESoftDelY bean = finder
|
||||
.query()
|
||||
.where()
|
||||
.eq("organization.uuid", uuid)
|
||||
.isNull("x")
|
||||
.findOne();
|
||||
|
||||
assertThat(bean).isNotNull();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user