mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#1524 - @History on @OneToMany with asOf() query and fetch(many property) gives PersistenceException: Error with property[6] dt[93]data[2018-11-01 14:56:18.015][java.sql.Timestamp]
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
package org.tests.model.history;
|
||||
|
||||
import io.ebean.annotation.History;
|
||||
import org.tests.model.draftable.BaseDomain;
|
||||
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.OneToMany;
|
||||
import java.util.List;
|
||||
|
||||
@History
|
||||
@Entity
|
||||
public class HiTOne extends BaseDomain {
|
||||
|
||||
String name;
|
||||
|
||||
String comments;
|
||||
|
||||
@OneToMany(cascade = CascadeType.ALL)
|
||||
List<HiTTwo> twos;
|
||||
|
||||
public HiTOne(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public HiTOne() {
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getComments() {
|
||||
return comments;
|
||||
}
|
||||
|
||||
public void setComments(String comments) {
|
||||
this.comments = comments;
|
||||
}
|
||||
|
||||
public List<HiTTwo> getTwos() {
|
||||
return twos;
|
||||
}
|
||||
|
||||
public void setTwos(List<HiTTwo> twos) {
|
||||
this.twos = twos;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package org.tests.model.history;
|
||||
|
||||
import io.ebean.annotation.History;
|
||||
import org.tests.model.draftable.BaseDomain;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
|
||||
@History
|
||||
@Entity
|
||||
public class HiTThree extends BaseDomain {
|
||||
|
||||
String three;
|
||||
|
||||
public HiTThree(String three) {
|
||||
this.three = three;
|
||||
}
|
||||
|
||||
public HiTThree() {
|
||||
}
|
||||
|
||||
public String getThree() {
|
||||
return three;
|
||||
}
|
||||
|
||||
public void setThree(String three) {
|
||||
this.three = three;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package org.tests.model.history;
|
||||
|
||||
import io.ebean.annotation.History;
|
||||
import org.tests.model.draftable.BaseDomain;
|
||||
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.OneToMany;
|
||||
import java.util.List;
|
||||
|
||||
@History
|
||||
@Entity
|
||||
public class HiTTwo extends BaseDomain {
|
||||
|
||||
String two;
|
||||
|
||||
@OneToMany(cascade = CascadeType.ALL)
|
||||
List<HiTThree> threes;
|
||||
|
||||
public HiTTwo(String two) {
|
||||
this.two = two;
|
||||
}
|
||||
|
||||
public String getTwo() {
|
||||
return two;
|
||||
}
|
||||
|
||||
public void setTwo(String two) {
|
||||
this.two = two;
|
||||
}
|
||||
|
||||
public List<HiTThree> getThrees() {
|
||||
return threes;
|
||||
}
|
||||
|
||||
public void setThrees(List<HiTThree> threes) {
|
||||
this.threes = threes;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package org.tests.model.history;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.Ebean;
|
||||
import org.ebeantest.LoggedSqlCollector;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class TestHistoryOneToMany extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
HiTOne one = new HiTOne("one");
|
||||
|
||||
HiTThree _31 = new HiTThree("3.1");
|
||||
HiTThree _32 = new HiTThree("3.2");
|
||||
HiTThree _33 = new HiTThree("3.3");
|
||||
HiTThree _34 = new HiTThree("3.4");
|
||||
|
||||
HiTTwo _21 = new HiTTwo("2.1");
|
||||
_21.getThrees().add(_31);
|
||||
_21.getThrees().add(_32);
|
||||
_21.getThrees().add(_33);
|
||||
|
||||
HiTTwo _22 = new HiTTwo("2.2");
|
||||
_22.getThrees().add(_34);
|
||||
|
||||
one.getTwos().add(_21);
|
||||
one.getTwos().add(_22);
|
||||
|
||||
|
||||
Ebean.save(one);
|
||||
|
||||
LoggedSqlCollector.start();
|
||||
|
||||
List<HiTOne> list = Ebean.find(HiTOne.class)
|
||||
.fetch("twos")
|
||||
.fetch("twos.threes")
|
||||
.where().ilike("name", "on%")
|
||||
.setMaxRows(10)
|
||||
.asOf(new Timestamp(System.currentTimeMillis()))
|
||||
.findList();
|
||||
|
||||
List<String> sql = LoggedSqlCollector.stop();
|
||||
|
||||
if (isH2()) {
|
||||
assertThat(sql).hasSize(2);
|
||||
assertThat(sql.get(0)).contains("from hi_tone_with_history t0 where (t0.sys_period_start <= ? and (t0.sys_period_end is null or t0.sys_period_end > ?)) and lower(t0.name) like ? escape'' order by t0.id limit 10");
|
||||
assertThat(sql.get(1)).contains("from hi_ttwo_with_history t0 left join hi_tthree_with_history t1 on t1.hi_ttwo_id = t0.id and (t1.sys_period_start <= ? and (t1.sys_period_end is null or t1.sys_period_end > ?)) where (t0.sys_period_start <= ? and (t0.sys_period_end is null or t0.sys_period_end > ?)) and (t0.hi_tone_id) in (? ) order by t0.id");
|
||||
}
|
||||
|
||||
assertThat(list).hasSize(1);
|
||||
assertThat(list.get(0).getTwos()).hasSize(2);
|
||||
assertThat(list.get(0).getTwos().get(0).getThrees()).hasSize(3);
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user