From df892f450985fa2ad910a29da2038e57ab5b5503 Mon Sep 17 00:00:00 2001 From: Tobias Date: Wed, 11 Jul 2018 15:52:56 +0200 Subject: [PATCH] Failing testcase with lazy fetch For some reason, all entities with an id starting with _ fails when lazy-fetching due to sort not being properly renamed. --- .../org/tests/model/lazywithid/Looney.java | 36 +++++++++++++++++++ .../model/lazywithid/TestColumnIdName.java | 26 ++++++++++++++ .../java/org/tests/model/lazywithid/Tune.java | 29 +++++++++++++++ 3 files changed, 91 insertions(+) create mode 100644 src/test/java/org/tests/model/lazywithid/Looney.java create mode 100644 src/test/java/org/tests/model/lazywithid/TestColumnIdName.java create mode 100644 src/test/java/org/tests/model/lazywithid/Tune.java diff --git a/src/test/java/org/tests/model/lazywithid/Looney.java b/src/test/java/org/tests/model/lazywithid/Looney.java new file mode 100644 index 000000000..a51758b3f --- /dev/null +++ b/src/test/java/org/tests/model/lazywithid/Looney.java @@ -0,0 +1,36 @@ +package org.tests.model.lazywithid; + +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.ManyToOne; + +@Entity +public class Looney { + @Id + public Long id; + + @ManyToOne + private Tune tune; + + private String name; + + public Looney(final String name) { + this.name = name; + } + + public Tune getTune() { + return tune; + } + + public void setTune(final Tune tune) { + this.tune = tune; + } + + public String getName() { + return name; + } + + public void setName(final String name) { + this.name = name; + } +} diff --git a/src/test/java/org/tests/model/lazywithid/TestColumnIdName.java b/src/test/java/org/tests/model/lazywithid/TestColumnIdName.java new file mode 100644 index 000000000..4d8a16106 --- /dev/null +++ b/src/test/java/org/tests/model/lazywithid/TestColumnIdName.java @@ -0,0 +1,26 @@ +package org.tests.model.lazywithid; + +import static org.junit.Assert.assertEquals; + +import java.util.List; + +import org.junit.Test; + +import io.ebean.BaseTestCase; +import io.ebean.Ebean; + +public class TestColumnIdName extends BaseTestCase { + @Test + public void test() { + + Tune tune = new Tune(); + tune.getLoonies().add(new Looney("Taz")); + Ebean.save(tune); + + final List fetchedCollection = Ebean.find(Tune.class).findList(); + + assertEquals(1, fetchedCollection.size()); + assertEquals(1, fetchedCollection.get(0).getLoonies().size()); + assertEquals("Taz", fetchedCollection.get(0).getLoonies().get(0).getName()); + } +} diff --git a/src/test/java/org/tests/model/lazywithid/Tune.java b/src/test/java/org/tests/model/lazywithid/Tune.java new file mode 100644 index 000000000..4054db960 --- /dev/null +++ b/src/test/java/org/tests/model/lazywithid/Tune.java @@ -0,0 +1,29 @@ +package org.tests.model.lazywithid; + +import java.util.List; + +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.OneToMany; + +import io.ebean.common.BeanList; + +@Entity +public class Tune { + @Id + @Column(name = "id") + public Long _id; + + @OneToMany(cascade = CascadeType.ALL) + private List loonies = new BeanList<>(); + + public List getLoonies() { + return loonies; + } + + public void setLoonies(final List loonies) { + this.loonies = loonies; + } +}