기본 질문 : @ 임베드 된 객체가 항상 인스턴스화되지 않는 이유는 무엇입니까?기본 데이터 유형 필드가없는 @ 내장 객체는 자동으로 인스턴스화되지 않습니다.
재미있는 관찰은 기본 데이터 유형 (int, boolean ...)을 포함하지 않거나 전에 만진 적이 없다면 Ebean이 @Embedded 객체를 인스턴스화하지 않는다는 것입니다. 예 :
@Entity
public class Embedder {
// getNotAutoInstantiated() will return null if this field was not touched before
@Embedded
private NotAutoInstantiated notAutoInstantiated = new NotAutoInstantiated();
// getAutoInstantiated() will always return an instance!
@Embedded
private AutoInstantiated autoInstantiated = new AutoInstantiated();
}
@Embeddable
public class AutoInstantiated {
// theKey is why this embedded object is always instantiated
private int theKey;
private String field1;
}
@Embeddable
public class NotAutoInstantiated {
private String field2;
}
여러 내장 된 개체 간의 필드 이름 충돌 문제가 발생할 수 있습니다. 일반적으로 JPA 제공자는 임베디드 오브젝트 필드를 상위 테이블의 컬럼에 맵핑합니다. 포함 된 필드 이름이 길면 데이터베이스에서 잘린 필드 이름이 생겨 결국 열 이름의 충돌로 끝날 수 있습니다. – Zagrev
예는 속일 수 있습니다. 이름은 내 코드에서 훨씬 짧으며 같은 접두어로 시작하지 않습니다. 그러나 예제에서조차 필드는 "not"와 "auto"로 시작하기 때문에 절사가 큰 문제는 아닙니다. – allprog
사실 "필드"와 "필드"에 대해 생각하고있었습니다. – Zagrev