Hibernate hbm.xml 파일의 일부 클래스를 JPA 주석으로 마이그레이션하고 있습니다.Hibernate/JPA에서 대소 문자를 구분하여 @Embedded 속성의 필드 제외
우리는 몇 군데에서 사용되는 임베디드 클래스 Address
을 보유하고 있습니다. 각 장소는 주소의 다른 하위 집합을 사용합니다.
(간결함을 위해 생략 게터/세터)이 고안 한 예에서,이 shippingAddress Address.country 사용하지만 billingAddress하지 않는 것을
@Embeddable
public class Address {
String email;
String address;
String city;
String state;
String zip;
String country;
}
@Entity
@Table(name="customer")
public class Customer {
@Embedded
@AttributeOverrides({
@AttributeOverride(name="address", [email protected](name="ship_addr"),
@AttributeOverride(name="city", [email protected](name="ship_city"),
@AttributeOverride(name="state", [email protected](name="ship_state"),
@AttributeOverride(name="zip", [email protected](name="ship_zip"),
@AttributeOverride(name="country", [email protected](name="ship_country")
})
Address shippingAddress;
@Embedded
@AttributeOverrides({
@AttributeOverride(name="address", [email protected](name="bill_addr"),
@AttributeOverride(name="city", [email protected](name="bill_city"),
@AttributeOverride(name="state", [email protected](name="bill_state"),
@AttributeOverride(name="zip", [email protected](name="bill_zip")
})
Address billingAddress;
}
참고; 둘 다 Address.email을 사용하지 않습니다.
Hibernate가 명시 적으로 제공하지 않은 모든 열에 대해 @Column
태그를 유추하는 것이 문제입니다.
모든 Address
필드에 @Transient
을 추가했지만, @AttributeOverride
은 @Transient
을 우회한 것으로 보입니다.
해결 방법이 있습니까?
문제는 이것이 우리 조직 전체에서 사용되는 일반적인 모델 클래스라는 것입니다. 이 클래스를 동작을 변경하지 않고 JPA로 마이그레이션하거나 30 개의 다른 팀이 코드를 조정하도록 강요하는 방법을 찾고 있습니다. – qualidafial
&at; 칼럼을 사용하는 것이 아니라 &at; Transient를 사용하는 JPA의 탈퇴 전환과 관련된 문제입니다. 이 아이디어는 어디서나 &at; 열 주석을 요구하지 않음으로써 JPA를 덜 침략 적으로 채택하는 것이 었습니다. 이는 우리를 물들게하고이 하나의 클래스를 기존 XML 구성에서 JPA 주석으로 마이그레이션하는 것을 불가능하게 만드는 부작용입니다. – qualidafial
모델을 변경할 수없는 경우 해결책이 표시되지 않습니다. 사용되지 않는 Address 속성을 무시하고 DB에 공백으로두면됩니다. 더러운 솔루션,하지만 최소한 침략. –