mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-22 15:10:02 +00:00
Test case for lazy @OneToOne beans with @History
Ebean produces an invalid query when trying to lazy load @OneToOne from a historical bean. This test asserts working behaviour.
This commit is contained in:
1 parent
0e548ec1c5
commit
67fc7cdb48
3 files changed
+93
No files matched your search
@@ -0,0 +1,32 @@
|
|||||||
|
package org.tests.model.history;
|
||||||
|
|
||||||
|
import io.ebean.annotation.History;
|
||||||
|
import javax.persistence.CascadeType;
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.OneToOne;
|
||||||
|
import org.tests.model.draftable.BaseDomain;
|
||||||
|
|
||||||
|
@History
|
||||||
|
@Entity
|
||||||
|
public class HistoryOneToOne extends BaseDomain {
|
||||||
|
|
||||||
|
String name;
|
||||||
|
|
||||||
|
@OneToOne(cascade = {CascadeType.REFRESH, CascadeType.REFRESH})
|
||||||
|
HistorylessOneToOne historylessOneToOne;
|
||||||
|
|
||||||
|
public HistoryOneToOne(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public HistoryOneToOne() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public HistorylessOneToOne getHistorylessOneToOne() {
|
||||||
|
return historylessOneToOne;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHistorylessOneToOne(final HistorylessOneToOne historylessOneToOne) {
|
||||||
|
this.historylessOneToOne = historylessOneToOne;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package org.tests.model.history;
|
||||||
|
|
||||||
|
import javax.persistence.CascadeType;
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.OneToOne;
|
||||||
|
import org.tests.model.draftable.BaseDomain;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
public class HistorylessOneToOne extends BaseDomain {
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
public HistorylessOneToOne() {}
|
||||||
|
|
||||||
|
public HistorylessOneToOne(final String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@OneToOne(mappedBy = "historylessOneToOne", cascade = CascadeType.ALL, orphanRemoval = true)
|
||||||
|
HistoryOneToOne historyOneToOne;
|
||||||
|
|
||||||
|
public HistoryOneToOne getHistoryOneToOne() {
|
||||||
|
return historyOneToOne;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHistoryOneToOne(final HistoryOneToOne historyOneToOne) {
|
||||||
|
this.historyOneToOne = historyOneToOne;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package org.tests.model.history;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
import io.ebean.DB;
|
||||||
|
import io.ebean.annotation.Platform;
|
||||||
|
import io.ebean.test.LoggedSql;
|
||||||
|
import io.ebean.xtest.BaseTestCase;
|
||||||
|
import io.ebean.xtest.IgnorePlatform;
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
import java.util.List;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
public class TestHistoryOneToOne extends BaseTestCase {
|
||||||
|
|
||||||
|
@IgnorePlatform({Platform.ORACLE, Platform.COCKROACH})
|
||||||
|
@Test
|
||||||
|
public void test() throws InterruptedException {
|
||||||
|
HistorylessOneToOne historylessOneToOne = new HistorylessOneToOne();
|
||||||
|
historylessOneToOne.setHistoryOneToOne(new HistoryOneToOne("one"));
|
||||||
|
DB.save(historylessOneToOne);
|
||||||
|
Thread.sleep(20);
|
||||||
|
LoggedSql.start();
|
||||||
|
|
||||||
|
HistoryOneToOne oneFetched = DB.find(HistoryOneToOne.class)
|
||||||
|
.asOf(new Timestamp(System.currentTimeMillis()))
|
||||||
|
.findOne();
|
||||||
|
|
||||||
|
assertThat(oneFetched.getHistorylessOneToOne().getHistoryOneToOne().getId()).isEqualTo(historylessOneToOne.getHistoryOneToOne().getId());
|
||||||
|
|
||||||
|
List<String> sql = LoggedSql.stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user