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.RetentionPolicy.RUNTIME;
042:
043: /**
044: * Designates a class whose mapping information is applied
045: * to the entities that inherit from it. A mapped superclass
046: * has no separate table defined for it.
047: *
048: * <p> A class designated with the <code>MappedSuperclass</code>
049: * annotation can be mapped in the same way as an entity except that the
050: * mappings will apply only to its subclasses since no table
051: * exists for the mapped superclass itself. When applied to the
052: * subclasses the inherited mappings will apply in the context
053: * of the subclass tables. Mapping information may be overridden
054: * in such subclasses by using the {@link AttributeOverride} and
055: * {@link AssociationOverride} annotations or corresponding XML elements.
056: *
057: * <pre>
058: * Example: Concrete class as a mapped superclass
059: *
060: * @MappedSuperclass
061: * public class Employee {
062: *
063: * @Id protected Integer empId;
064: * @Version protected Integer version;
065: * @ManyToOne @JoinColumn(name="ADDR")
066: * protected Address address;
067: *
068: * public Integer getEmpId() { ... }
069: * public void setEmpId(Integer id) { ... }
070: * public Address getAddress() { ... }
071: * public void setAddress(Address addr) { ... }
072: * }
073: *
074: * // Default table is FTEMPLOYEE table
075: * @Entity
076: * public class FTEmployee extends Employee {
077: *
078: * // Inherited empId field mapped to FTEMPLOYEE.EMPID
079: * // Inherited version field mapped to FTEMPLOYEE.VERSION
080: * // Inherited address field mapped to FTEMPLOYEE.ADDR fk
081: *
082: *
083: * // Defaults to FTEMPLOYEE.SALARY
084: *
085: * protected Integer salary;
086: *
087: *
088: * public FTEmployee() {}
089: *
090: *
091: * public Integer getSalary() { ... }
092: *
093: * public void setSalary(Integer salary) { ... }
094: * }
095: *
096: * @Entity @Table(name="PT_EMP")
097: * @AssociationOverride(name="address",
098: *
099: *
100: * joincolumns=@JoinColumn(name="ADDR_ID"))
101: * public class PartTimeEmployee extends Employee {
102: *
103: * // Inherited empId field mapped to PT_EMP.EMPID
104: * // Inherited version field mapped to PT_EMP.VERSION
105: * // address field mapping overridden to PT_EMP.ADDR_ID fk
106: * @Column(name="WAGE")
107: * protected Float hourlyWage;
108: *
109: * public PartTimeEmployee() {}
110: *
111: * public Float getHourlyWage() { ... }
112: * public void setHourlyWage(Float wage) { ... }
113: * }
114: *
115: * Example: Non-entity superclass
116: *
117: * public class Cart {
118: *
119: * // This state is transient
120: * Integer operationCount;
121: *
122: * public Cart() { operationCount = 0; }
123: * public Integer getOperationCount() { return operationCount; }
124: * public void incrementOperationCount() { operationCount++; }
125: * }
126: *
127: * @Entity
128: * public class ShoppingCart extends Cart {
129: *
130: * Collection<Item> items = new Vector<Item>();
131: *
132: * public ShoppingCart() { super(); }
133: *
134: *
135: * ...
136: *
137: * @OneToMany
138: * public Collection<Item> getItems() { return items; }
139: * public void addItem(Item item) {
140: * items.add(item);
141: * incrementOperationCount();
142: * }
143: * }
144: * </pre>
145: *
146: * @since Java Persistence 1.0
147: */
148: @Target({TYPE})
149: @Retention(RUNTIME)
150: public @interface MappedSuperclass {
151: }
|