diff --git a/src/main/java/io/ebeaninternal/server/deploy/BeanProperty.java b/src/main/java/io/ebeaninternal/server/deploy/BeanProperty.java index 8b0650f54..231f48357 100644 --- a/src/main/java/io/ebeaninternal/server/deploy/BeanProperty.java +++ b/src/main/java/io/ebeaninternal/server/deploy/BeanProperty.java @@ -1285,7 +1285,7 @@ public class BeanProperty implements ElPropertyValue, Property, STreeProperty { * Return true if this is a ManyToMany with history support (on the intersection table). */ public boolean isManyToManyWithHistory() { - return !excludedFromHistory && descriptor.isHistorySupport(); + return false; } /** diff --git a/src/main/java/io/ebeaninternal/server/deploy/BeanPropertyAssocMany.java b/src/main/java/io/ebeaninternal/server/deploy/BeanPropertyAssocMany.java index 2058f0e56..fa7eca5ef 100644 --- a/src/main/java/io/ebeaninternal/server/deploy/BeanPropertyAssocMany.java +++ b/src/main/java/io/ebeaninternal/server/deploy/BeanPropertyAssocMany.java @@ -208,6 +208,11 @@ public class BeanPropertyAssocMany extends BeanPropertyAssoc implements ST } } + @Override + public boolean isManyToManyWithHistory() { + return manyToMany && !excludedFromHistory && descriptor.isHistorySupport(); + } + @Override protected void docStoreIncludeByDefault(PathProperties pathProps) { // by default not including "Many" properties in document store diff --git a/src/test/java/org/tests/model/history/HiTOne.java b/src/test/java/org/tests/model/history/HiTOne.java new file mode 100644 index 000000000..36018af05 --- /dev/null +++ b/src/test/java/org/tests/model/history/HiTOne.java @@ -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 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 getTwos() { + return twos; + } + + public void setTwos(List twos) { + this.twos = twos; + } +} diff --git a/src/test/java/org/tests/model/history/HiTThree.java b/src/test/java/org/tests/model/history/HiTThree.java new file mode 100644 index 000000000..2b7ae5473 --- /dev/null +++ b/src/test/java/org/tests/model/history/HiTThree.java @@ -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; + } +} diff --git a/src/test/java/org/tests/model/history/HiTTwo.java b/src/test/java/org/tests/model/history/HiTTwo.java new file mode 100644 index 000000000..18c2d299d --- /dev/null +++ b/src/test/java/org/tests/model/history/HiTTwo.java @@ -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 threes; + + public HiTTwo(String two) { + this.two = two; + } + + public String getTwo() { + return two; + } + + public void setTwo(String two) { + this.two = two; + } + + public List getThrees() { + return threes; + } + + public void setThrees(List threes) { + this.threes = threes; + } +} diff --git a/src/test/java/org/tests/model/history/TestHistoryOneToMany.java b/src/test/java/org/tests/model/history/TestHistoryOneToMany.java new file mode 100644 index 000000000..7332b81e2 --- /dev/null +++ b/src/test/java/org/tests/model/history/TestHistoryOneToMany.java @@ -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 list = Ebean.find(HiTOne.class) + .fetch("twos") + .fetch("twos.threes") + .where().ilike("name", "on%") + .setMaxRows(10) + .asOf(new Timestamp(System.currentTimeMillis())) + .findList(); + + List 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); + + } +}