1 Reply Latest reply on Apr 18, 2005 8:24 AM by Emmanuel Bernard

    @AttributeOverride and nested components

    Chris Richardson Newbie

      How do I use @AttributeOverride to changing the mapping when one component is nested inside another.

      I have the following consisting of an entity and two embeddable classes, one of which is nested inside the other.

      @Entity(access = AccessType.FIELD)
      public class PendingOrder {
       private Address deliveryAddress;
       private PaymentInformation paymentInformation;
      @Embeddable(access = AccessType.FIELD)
      public class Address {
       private String street1;
       private String street2;
      @Embeddable(access = AccessType.FIELD)
      public class PaymentInformation {
       protected String number;
       private Address address;

      Using @AttributeOverride to changing the mapping of the PendingOrder.deliveryAddress field is straightforward:
       @Embedded( {
       @AttributeOverride(name = "street1", column = { @Column(name = "DELIVERY_STREET1") }),
       @AttributeOverride(name = "street2", column = { @Column(name = "DELIVERY_STREET2") }),
       @AttributeOverride(name = "city", column = @Column(name = "DELIVERY_CITY")),
       @AttributeOverride(name = "state", column = @Column(name = "DELIVERY_STATE")),
       @AttributeOverride(name = "zip", column = @Column(name = "DELIVERY_ZIP")) })
       private Address deliveryAddress;

      But what about using @AttributeOverride in the PendingOrder class to change the mapping for PendingOrder.paymentInformation.address?
      That doesn't seem to be possible.

      I had to use @AttributeOverride inside the PaymentInformation class to change the mapping for PaymentInformation.address but that doesn't seem right.