001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common Development
008: * and Distribution License("CDDL") (collectively, the "License"). You
009: * may not use this file except in compliance with the License. You can obtain
010: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
011: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
012: * language governing permissions and limitations under the License.
013: *
014: * When distributing the software, include this License Header Notice in each
015: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
016: * Sun designates this particular file as subject to the "Classpath" exception
017: * as provided by Sun in the GPL Version 2 section of the License file that
018: * accompanied this code. If applicable, add the following below the License
019: * Header, with the fields enclosed by brackets [] replaced by your own
020: * identifying information: "Portions Copyrighted [year]
021: * [name of copyright owner]"
022: *
023: * Contributor(s):
024: *
025: * If you wish your version of this file to be governed by only the CDDL or
026: * only the GPL Version 2, indicate your decision by adding "[Contributor]
027: * elects to include this software in this distribution under the [CDDL or GPL
028: * Version 2] license." If you don't indicate a single choice of license, a
029: * recipient has the option to distribute your version of this file under
030: * either the CDDL, the GPL Version 2 or to extend the choice of license to
031: * its licensees as provided above. However, if you add GPL Version 2 code
032: * and therefore, elected the GPL Version 2 license, then the option applies
033: * only if the new code is made subject to such option by the copyright
034: * holder.
035: */
036: package javax.persistence;
037:
038: import java.lang.annotation.Target;
039: import java.lang.annotation.Retention;
040: import static java.lang.annotation.ElementType.TYPE;
041: import static java.lang.annotation.ElementType.METHOD;
042: import static java.lang.annotation.ElementType.FIELD;
043: import static java.lang.annotation.RetentionPolicy.RUNTIME;
044:
045: /**
046: * The <code>AttributeOverride</code> annotation is used to
047: * override the mapping of a {@link Basic} (whether explicit or
048: * default) property or field or Id property or field.
049: *
050: * <p> The <code>AttributeOverride</code> annotation may be
051: * applied to an entity that extends a mapped superclass or to
052: * an embedded field or property to override a basic mapping
053: * defined by the mapped superclass or embeddable class. If the
054: * <code>AttributeOverride</code> annotation is not specified,
055: * the column is mapped the same as in the original mapping.
056: *
057: * <pre>
058: * <p> Example:
059: *
060: * @MappedSuperclass
061: * public class Employee {
062: * @Id protected Integer id;
063: * @Version protected Integer version;
064: * protected String address;
065: * public Integer getId() { ... }
066: * public void setId(Integer id) { ... }
067: * public String getAddress() { ... }
068: * public void setAddress(String address) { ... }
069: * }
070: *
071: * @Entity
072: * @AttributeOverride(name="address", column=@Column(name="ADDR"))
073: * public class PartTimeEmployee extends Employee {
074: * // address field mapping overridden to ADDR
075: * protected Float wage();
076: * public Float getHourlyWage() { ... }
077: * public void setHourlyWage(Float wage) { ... }
078: * }
079: * </pre>
080: *
081: * @see Embedded
082: * @see Embeddable
083: * @see MappedSuperclass
084: *
085: * @since Java Persistence 1.0
086: */
087: @Target({TYPE,METHOD,FIELD})
088: @Retention(RUNTIME)
089: public @interface AttributeOverride {
090:
091: /**
092: * (Required) The name of the property whose mapping is being
093: * overridden if property-based access is being used, or the
094: * name of the field if field-based access is used.
095: */
096: String name();
097:
098: /**
099: * (Required) The column that is being mapped to the persistent
100: * attribute. The mapping type will remain the same as is
101: * defined in the embeddable class or mapped superclass.
102: */
103: Column column();
104: }
|