mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#2156 - Using @OneToOne(targetEntity...) with Interface field results in BeanNotRegisteredException (#2160)
This commit is contained in:
@@ -16,7 +16,7 @@ public class TestManyOneInterface extends BaseTestCase {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
IAddress a = new Address();
|
||||
IAddress a = new Address("hello");
|
||||
|
||||
IPerson p = new Person();
|
||||
|
||||
|
||||
@@ -15,6 +15,10 @@ public class Address implements IAddress {
|
||||
|
||||
private String street;
|
||||
|
||||
public Address(String street) {
|
||||
this.street = street;
|
||||
}
|
||||
|
||||
public long getOid() {
|
||||
return oid;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
package org.tests.model.interfaces;
|
||||
|
||||
public interface IPersona {
|
||||
|
||||
String persona();
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package org.tests.model.interfaces;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
@Entity
|
||||
public class Persona implements IPersona {
|
||||
|
||||
@Id
|
||||
private long id;
|
||||
|
||||
@Version
|
||||
private int version;
|
||||
|
||||
private final String persona;
|
||||
|
||||
@OneToOne(orphanRemoval = true, fetch = FetchType.LAZY, targetEntity = Person.class)
|
||||
private IPerson person;
|
||||
|
||||
public Persona(String persona) {
|
||||
this.persona = persona;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String persona() {
|
||||
return persona;
|
||||
}
|
||||
|
||||
public void setPerson(IPerson person) {
|
||||
this.person = person;
|
||||
}
|
||||
|
||||
public IPerson getPerson() {
|
||||
return person;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package org.tests.model.interfaces;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.DB;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class TestTargetEntity extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
Person person = setup();
|
||||
|
||||
Persona persona = new Persona("junk");
|
||||
persona.setPerson(person);
|
||||
DB.save(persona);
|
||||
|
||||
Persona found = DB.find(Persona.class, persona.getId());
|
||||
assertThat(found).isNotNull();
|
||||
assertThat(found.persona()).isEqualTo("junk");
|
||||
assertThat(found.getPerson().getDefaultAddress().getStreet()).isEqualTo("street");
|
||||
|
||||
DB.delete(persona);
|
||||
DB.delete(person);
|
||||
DB.delete(person.getDefaultAddress());
|
||||
}
|
||||
|
||||
private Person setup() {
|
||||
Address address = new Address("street");
|
||||
DB.save(address);
|
||||
Person person = new Person();
|
||||
person.setDefaultAddress(address);
|
||||
DB.save(person);
|
||||
return person;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user