#1497 - SQL Error with @History + @SoftDelete + @OneToOne fetch=FetchType.EAGER

This commit is contained in:
rob bygrave
2018-10-04 19:59:36 +13:00
parent 2c04430185
commit c27749ae2d
5 changed files with 162 additions and 6 deletions
@@ -134,27 +134,40 @@ public interface SpiQuery<T> extends Query<T>, TxnProfileEventCodes {
/**
* Includes soft deletes rows in the result.
*/
SOFT_DELETED,
SOFT_DELETED(false),
/**
* Query runs against draft tables.
*/
DRAFT,
DRAFT(false),
/**
* Query runs against current data (normal).
*/
CURRENT,
CURRENT(false),
/**
* Query runs potentially returning many versions of the same bean.
*/
VERSIONS,
VERSIONS(true),
/**
* Query runs 'As Of' a given date time.
*/
AS_OF;
AS_OF(true);
private final boolean history;
TemporalMode(boolean history) {
this.history = history;
}
/**
* Return true if this is a history query.
*/
public boolean isHistory() {
return history;
}
/**
* Return the mode of the query of if null return CURRENT mode.
@@ -217,7 +217,7 @@ class CQueryBuilder {
* Return the history support if this query needs it (is a 'as of' type query).
*/
<T> CQueryHistorySupport getHistorySupport(SpiQuery<T> query) {
return query.getTemporalMode() != SpiQuery.TemporalMode.CURRENT ? historySupport : null;
return query.getTemporalMode().isHistory() ? historySupport : null;
}
/**
@@ -0,0 +1,62 @@
package org.tests.model.history;
import io.ebean.annotation.History;
import io.ebean.annotation.SoftDelete;
import org.tests.model.draftable.BaseDomain;
import javax.persistence.Entity;
import javax.persistence.OneToOne;
@History
@Entity
public class HsdSetting extends BaseDomain {
String key;
String val;
@SoftDelete
boolean deleted;
@OneToOne
private HsdUser user;
public HsdSetting(String key) {
this.key = key;
}
public HsdSetting() {
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public String getVal() {
return val;
}
public void setVal(String val) {
this.val = val;
}
public boolean isDeleted() {
return deleted;
}
public void setDeleted(boolean deleted) {
this.deleted = deleted;
}
public HsdUser getUser() {
return user;
}
public void setUser(HsdUser user) {
this.user = user;
}
}
@@ -0,0 +1,54 @@
package org.tests.model.history;
import io.ebean.annotation.History;
import io.ebean.annotation.SoftDelete;
import org.tests.model.draftable.BaseDomain;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.OneToOne;
@History
@Entity
public class HsdUser extends BaseDomain {
String name;
@SoftDelete
boolean deleted;
@OneToOne(mappedBy = "user", fetch = FetchType.EAGER, cascade = CascadeType.ALL)
HsdSetting setting;
public HsdUser(String name) {
this.name = name;
}
public HsdUser() {
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public boolean isDeleted() {
return deleted;
}
public void setDeleted(boolean deleted) {
this.deleted = deleted;
}
public HsdSetting getSetting() {
return setting;
}
public void setSetting(HsdSetting setting) {
this.setting = setting;
}
}
@@ -0,0 +1,27 @@
package org.tests.model.history;
import io.ebean.BaseTestCase;
import io.ebean.Ebean;
import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;
public class TestHistorySoftDeleteOneToOne extends BaseTestCase {
@Test
public void findOne() {
HsdUser u1 = new HsdUser("u1");
Ebean.save(u1);
Ebean.delete(u1);
HsdUser one = Ebean.find(HsdUser.class)
.setId(u1.getId())
.setIncludeSoftDeletes()
.findOne();
assertThat(one).isNotNull();
}
}