mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#2044 - Using @AttributeOverrides breaking generated SQL (when override nullable and no column name)
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
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 EPerson2 {
|
||||
|
||||
@Id
|
||||
long id;
|
||||
|
||||
@Version
|
||||
long version;
|
||||
|
||||
String name;
|
||||
|
||||
String notes;
|
||||
|
||||
@Embedded
|
||||
@AttributeOverrides({
|
||||
@AttributeOverride(name = "city", column = @Column(nullable = false)),
|
||||
@AttributeOverride(name = "status", column = @Column(nullable = false))
|
||||
})
|
||||
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 String getNotes() {
|
||||
return notes;
|
||||
}
|
||||
|
||||
public void setNotes(String notes) {
|
||||
this.notes = notes;
|
||||
}
|
||||
|
||||
public EAddress getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public void setAddress(EAddress address) {
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package org.tests.model.embedded;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.DB;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
public class TestEmbeddedNullableOverride extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
EPerson2 person = new EPerson2();
|
||||
person.setName("foo");
|
||||
|
||||
EAddress address = new EAddress();
|
||||
address.setCity("myCity");
|
||||
address.setStatus(EAddressStatus.TWO);
|
||||
person.setAddress(address);
|
||||
|
||||
DB.save(person);
|
||||
|
||||
final EPerson2 found = DB.find(EPerson2.class, person.getId());
|
||||
|
||||
assertNotNull(found);
|
||||
assertNotNull(found.getAddress());
|
||||
assertThat(found.getAddress().getCity()).isEqualTo("myCity");
|
||||
assertThat(found.getAddress().getStatus()).isEqualTo(EAddressStatus.TWO);
|
||||
assertThat(found.getAddress().getStreet()).isNull();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user