mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#2044 - Using @AttributeOverrides when override nullable
This commit is contained in:
@@ -1,23 +1,21 @@
|
||||
package org.tests.embedded;
|
||||
|
||||
import io.ebean.Ebean;
|
||||
import io.ebean.DB;
|
||||
import org.junit.Test;
|
||||
import org.tests.model.embedded.EAddress;
|
||||
import org.tests.model.embedded.EAddressStatus;
|
||||
import org.tests.model.embedded.EPerson;
|
||||
import org.tests.model.embedded.EPerson3;
|
||||
|
||||
public class TestEmbeddedEmpty {
|
||||
|
||||
@Test
|
||||
public void insertEmptyEmbedded() {
|
||||
|
||||
EPerson person = new EPerson();
|
||||
EPerson3 person = new EPerson3();
|
||||
person.setName("with empty embedded");
|
||||
|
||||
// set empty embedded bean
|
||||
person.setAddress(new EAddress());
|
||||
|
||||
Ebean.save(person);
|
||||
DB.save(person);
|
||||
|
||||
// treat all embedded properties as loaded
|
||||
person.getAddress().getCity();
|
||||
@@ -28,7 +26,7 @@ public class TestEmbeddedEmpty {
|
||||
|
||||
EAddressStatus.TWO.doIt();
|
||||
|
||||
Ebean.find(EPerson.class)
|
||||
DB.find(EPerson3.class)
|
||||
.where().eq("address.status", EAddressStatus.TWO)
|
||||
.findList();
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.tests.model.embedded;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Embeddable;
|
||||
import javax.persistence.EnumType;
|
||||
import javax.persistence.Enumerated;
|
||||
@@ -7,6 +8,7 @@ import javax.persistence.Enumerated;
|
||||
@Embeddable
|
||||
public class EAddress {
|
||||
|
||||
@Column(nullable = false)
|
||||
String street;
|
||||
|
||||
String suburb;
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
package org.tests.model.embedded;
|
||||
|
||||
import javax.persistence.AttributeOverride;
|
||||
import javax.persistence.AttributeOverrides;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Embedded;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Version;
|
||||
|
||||
@Entity
|
||||
public class EPerson3 {
|
||||
|
||||
@Id
|
||||
long id;
|
||||
|
||||
@Version
|
||||
long version;
|
||||
|
||||
String name;
|
||||
|
||||
@Embedded
|
||||
@AttributeOverrides({
|
||||
@AttributeOverride(name = "street", column = @Column())
|
||||
})
|
||||
EAddress address;
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public long getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(long version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public EAddress getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public void setAddress(EAddress address) {
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user