mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#783 - tests for ... HistoryExclude Many-to-Many Query-Generation Error
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
package com.avaje.tests.model.history;
|
||||
|
||||
import com.avaje.tests.model.draftable.BaseDomain;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.ManyToMany;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@Entity
|
||||
public class HeDoc extends BaseDomain {
|
||||
|
||||
String name;
|
||||
|
||||
@ManyToMany(mappedBy = "docs")
|
||||
List<HeLink> links;
|
||||
|
||||
public HeDoc(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public List<HeLink> getLinks() {
|
||||
return links;
|
||||
}
|
||||
|
||||
public void setLinks(List<HeLink> links) {
|
||||
this.links = links;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package com.avaje.tests.model.history;
|
||||
|
||||
import com.avaje.ebean.annotation.History;
|
||||
import com.avaje.ebean.annotation.HistoryExclude;
|
||||
import com.avaje.tests.model.draftable.BaseDomain;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.ManyToMany;
|
||||
import java.util.List;
|
||||
|
||||
@History
|
||||
@Entity
|
||||
public class HeLink extends BaseDomain {
|
||||
|
||||
String name;
|
||||
|
||||
String location;
|
||||
|
||||
String comment;
|
||||
|
||||
@HistoryExclude
|
||||
@ManyToMany
|
||||
List<HeDoc> docs;
|
||||
|
||||
public HeLink(String name, String location) {
|
||||
this.name = name;
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
public HeLink() {
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
public void setLocation(String location) {
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
public String getComment() {
|
||||
return comment;
|
||||
}
|
||||
|
||||
public void setComment(String comment) {
|
||||
this.comment = comment;
|
||||
}
|
||||
|
||||
public List<HeDoc> getDocs() {
|
||||
return docs;
|
||||
}
|
||||
|
||||
public void setDocs(List<HeDoc> docs) {
|
||||
this.docs = docs;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.avaje.tests.model.history;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
|
||||
import static org.assertj.core.api.StrictAssertions.assertThat;
|
||||
|
||||
public class TestHistoryExclude extends BaseTestCase {
|
||||
|
||||
private HeLink link;
|
||||
|
||||
private void prepare() {
|
||||
if (link == null) {
|
||||
HeDoc docA = new HeDoc("doca");
|
||||
HeDoc docB = new HeDoc("docb");
|
||||
docA.save();
|
||||
docB.save();
|
||||
|
||||
link = new HeLink("some", "link");
|
||||
link.getDocs().add(docA);
|
||||
link.getDocs().add(docB);
|
||||
link.save();
|
||||
}
|
||||
}
|
||||
@Test
|
||||
public void testLazyLoad() {
|
||||
|
||||
prepare();
|
||||
|
||||
HeLink linkFound = Ebean.find(HeLink.class, link.getId());
|
||||
linkFound.getDocs().size();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAsOfThenLazy() {
|
||||
|
||||
prepare();
|
||||
|
||||
HeLink linkFound = Ebean.find(HeLink.class)
|
||||
.asOf(new Timestamp(System.currentTimeMillis()))
|
||||
.setId(link.getId())
|
||||
.findUnique();
|
||||
|
||||
assertThat(linkFound.getDocs().size()).isEqualTo(2);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user