mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#1804 - Kotlin: Generating collection with wildcard type - Get error BeanNotRegisteredException: Error with association to [null] from [...Foo.manyProperty]. Is null registered?
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
package org.tests.o2m;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.Version;
|
||||
|
||||
@Entity
|
||||
public class OmBasicChild {
|
||||
|
||||
@Id
|
||||
private long id;
|
||||
|
||||
private final String name;
|
||||
|
||||
@ManyToOne
|
||||
private final OmBasicParent parent;
|
||||
|
||||
@Version
|
||||
private long version;
|
||||
|
||||
public OmBasicChild(String name, OmBasicParent parent) {
|
||||
this.name = name;
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public OmBasicParent getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
public long getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(long version) {
|
||||
this.version = version;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package org.tests.o2m;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.Version;
|
||||
import java.util.List;
|
||||
|
||||
import static javax.persistence.CascadeType.ALL;
|
||||
|
||||
@Entity
|
||||
public class OmBasicParent {
|
||||
|
||||
@Id
|
||||
private long id;
|
||||
|
||||
private final String name;
|
||||
|
||||
@Version
|
||||
private long version;
|
||||
|
||||
/**
|
||||
* Not really sensible Java code here but Kotlin can generate
|
||||
* a collection type that looks like this
|
||||
*/
|
||||
@OneToMany(cascade = ALL, mappedBy = "parent")
|
||||
private List<? extends OmBasicChild> children;
|
||||
|
||||
public OmBasicParent(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public long getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(long version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public List<? extends OmBasicChild> getChildren() {
|
||||
return children;
|
||||
}
|
||||
|
||||
public void setChildren(List<? extends OmBasicChild> children) {
|
||||
this.children = children;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package org.tests.o2m;
|
||||
|
||||
import io.ebean.DB;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class TestOneToManyWildcard {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
OmBasicParent parent = new OmBasicParent("p1");
|
||||
OmBasicChild c1 = new OmBasicChild("c1", parent);
|
||||
OmBasicChild c2 = new OmBasicChild("c2", parent);
|
||||
|
||||
DB.save(parent);
|
||||
DB.saveAll(Arrays.asList(c1, c2));
|
||||
|
||||
// we can't add to this in Java but Kotlin can
|
||||
//parent.getChildren().add(c1);
|
||||
|
||||
// exercise
|
||||
final OmBasicParent found = DB.find(OmBasicParent.class)
|
||||
.where().idEq(parent.getId())
|
||||
.findOne();
|
||||
|
||||
assertThat(found).isNotNull();
|
||||
assertThat(found.getChildren()).hasSize(2);
|
||||
|
||||
DB.delete(parent);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user