javax.persistence

Annotation Type AttributeOverride


  • @Target(value={TYPE,METHOD,FIELD})
     @Retention(value=RUNTIME)
    public @interface AttributeOverride
    Used to override the mapping of a Basic (whether explicit or default) property or field or Id property or field.

    May be applied to an entity that extends a mapped superclass or to an embedded field or property to override a basic mapping or id mapping defined by the mapped superclass or embeddable class (or embeddable class of one of its attributes).

    May be applied to an element collection containing instances of an embeddable class or to a map collection whose key and/or value is an embeddable class. When AttributeOverride is applied to a map, "key." or "value." must be used to prefix the name of the attribute that is being overridden in order to specify it as part of the map key or map value.

    To override mappings at multiple levels of embedding, a dot (".") notation form must be used in the name element to indicate an attribute within an embedded attribute. The value of each identifier used with the dot notation is the name of the respective embedded field or property.

    If AttributeOverride is not specified, the column is mapped the same as in the original mapping.

        Example 1:
    
        @MappedSuperclass
        public class Employee {
            @Id protected Integer id;
            @Version protected Integer version;
            protected String address;
            public Integer getId() { ... }
            public void setId(Integer id) { ... }
            public String getAddress() { ... }
            public void setAddress(String address) { ... }
        }
    
        @Entity
        @AttributeOverride(name="address", column=@Column(name="ADDR"))
        public class PartTimeEmployee extends Employee {
            // address field mapping overridden to ADDR
            protected Float wage();
            public Float getHourlyWage() { ... }
            public void setHourlyWage(Float wage) { ... }
        }
     
    
        Example 2:
    
        @Embeddable public class Address {
            protected String street;
            protected String city;
            protected String state;
            @Embedded protected Zipcode zipcode;
        }
    
        @Embeddable public class Zipcode {
            protected String zip;
            protected String plusFour;
        }
    
        @Entity public class Customer {
            @Id protected Integer id;
            protected String name;
            @AttributeOverrides({
                @AttributeOverride(name="state",
                                   column=@Column(name="ADDR_STATE")),
                @AttributeOverride(name="zipcode.zip",
                                   column=@Column(name="ADDR_ZIP"))
            })
            @Embedded protected Address address;
            ...
        }
    
    
        Example 3:
    
        @Entity public class PropertyRecord {
            @EmbeddedId PropertyOwner owner;
            @AttributeOverrides({
                @AttributeOverride(name="key.street", 
                                   column=@Column(name="STREET_NAME")),
                @AttributeOverride(name="value.size", 
                                   column=@Column(name="SQUARE_FEET")),
                @AttributeOverride(name="value.tax", 
                                   column=@Column(name="ASSESSMENT"))
            })
           @ElementCollection
           Map<Address, PropertyInfo> parcels;
        }
    
       @Embeddable public class PropertyInfo {
           Integer parcelNumber;
           Integer size;
           BigDecimal tax;
       }
    
     
    Since:
    Java Persistence 1.0
    See Also:
    Embedded, Embeddable, MappedSuperclass, AssociationOverride
    • Required Element Summary

      Required Elements 
      Modifier and Type Required Element and Description
      Column column
      (Required) The column that is being mapped to the persistent attribute.
      String name
      (Required) The name of the property whose mapping is being overridden if property-based access is being used, or the name of the field if field-based access is used.

      Eerste pagina van API Java Inhoudsopgave Haut

    • Element Detail

      • name

        public abstract String name
        (Required) The name of the property whose mapping is being overridden if property-based access is being used, or the name of the field if field-based access is used.
      • column

        public abstract Column column
        (Required) The column that is being mapped to the persistent attribute. The mapping type will remain the same as is defined in the embeddable class or mapped superclass.

Nederlandse vertaling

U hebt gevraagd om deze site in het Nederlands te bezoeken. Voor nu wordt alleen de interface vertaald, maar nog niet alle inhoud.

Als je me wilt helpen met vertalingen, is je bijdrage welkom. Het enige dat u hoeft te doen, is u op de site registreren en mij een bericht sturen waarin u wordt gevraagd om u toe te voegen aan de groep vertalers, zodat u de gewenste pagina's kunt vertalen. Een link onderaan elke vertaalde pagina geeft aan dat u de vertaler bent en heeft een link naar uw profiel.

Bij voorbaat dank.

Document heeft de 11/06/2005 gemaakt, de laatste keer de 18/08/2025 gewijzigd
Bron van het afgedrukte document:https://www.gaudry.be/nl/java-api-javaee-rf-javax/persistence/AttributeOverride.html

De infobrol is een persoonlijke site waarvan de inhoud uitsluitend mijn verantwoordelijkheid is. De tekst is beschikbaar onder CreativeCommons-licentie (BY-NC-SA). Meer info op de gebruiksvoorwaarden en de auteur.

Referenties

  1. Bekijk - html-document Taal van het document:fr Manuel PHP : https://docs.oracle.com, AttributeOverride (Java(TM) EE 7 Specification APIs)

Deze verwijzingen en links verwijzen naar documenten die geraadpleegd zijn tijdens het schrijven van deze pagina, of die aanvullende informatie kunnen geven, maar de auteurs van deze bronnen kunnen niet verantwoordelijk worden gehouden voor de inhoud van deze pagina.
De auteur van deze site is als enige verantwoordelijk voor de manier waarop de verschillende concepten, en de vrijheden die met de referentiewerken worden genomen, hier worden gepresenteerd. Vergeet niet dat u meerdere broninformatie moet doorgeven om het risico op fouten te verkleinen.