001/*
002 * Copyright (c) 2008, 2009, 2011 Oracle, Inc. All rights reserved.
003 *
004 * This program and the accompanying materials are made available under the
005 * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
006 * which accompanies this distribution.  The Eclipse Public License is available
007 * at http://www.eclipse.org/legal/epl-v10.html and the Eclipse Distribution License
008 * is available at http://www.eclipse.org/org/documents/edl-v10.php.
009 */
010package javax.persistence;
011
012import java.lang.annotation.Documented;
013import java.lang.annotation.Retention;
014import java.lang.annotation.Target;
015
016import static java.lang.annotation.ElementType.TYPE;
017import static java.lang.annotation.RetentionPolicy.RUNTIME;
018
019/**
020 * Designates a class whose mapping information is applied
021 * to the entities that inherit from it. A mapped superclass
022 * has no separate table defined for it.
023 * <p>
024 * <p> A class designated with the <code>MappedSuperclass</code>
025 * annotation can be mapped in the same way as an entity except that the
026 * mappings will apply only to its subclasses since no table
027 * exists for the mapped superclass itself. When applied to the
028 * subclasses the inherited mappings will apply in the context
029 * of the subclass tables. Mapping information may be overridden
030 * in such subclasses by using the <code>AttributeOverride</code> and
031 * <code>AssociationOverride</code> annotations or corresponding XML elements.
032 * <p>
033 * <pre>
034 *    Example: Concrete class as a mapped superclass
035 *
036 *    &#064;MappedSuperclass
037 *    public class Employee {
038 *
039 *        &#064;Id protected Integer empId;
040 *        &#064;Version protected Integer version;
041 *        &#064;ManyToOne &#064;JoinColumn(name="ADDR")
042 *        protected Address address;
043 *
044 *        public Integer getEmpId() { ... }
045 *        public void setEmpId(Integer id) { ... }
046 *        public Address getAddress() { ... }
047 *        public void setAddress(Address addr) { ... }
048 *    }
049 *
050 *    // Default table is FTEMPLOYEE table
051 *    &#064;Entity
052 *    public class FTEmployee extends Employee {
053 *
054 *        // Inherited empId field mapped to FTEMPLOYEE.EMPID
055 *        // Inherited version field mapped to FTEMPLOYEE.VERSION
056 *        // Inherited address field mapped to FTEMPLOYEE.ADDR fk
057 *
058 *        // Defaults to FTEMPLOYEE.SALARY
059 *        protected Integer salary;
060 *
061 *        public FTEmployee() {}
062 *
063 *        public Integer getSalary() { ... }
064 *
065 *        public void setSalary(Integer salary) { ... }
066 *    }
067 *
068 *    &#064;Entity &#064;Table(name="PT_EMP")
069 *    &#064;AssociationOverride(
070 *        name="address",
071 *        joincolumns=&#064;JoinColumn(name="ADDR_ID"))
072 *    public class PartTimeEmployee extends Employee {
073 *
074 *        // Inherited empId field mapped to PT_EMP.EMPID
075 *        // Inherited version field mapped to PT_EMP.VERSION
076 *        // address field mapping overridden to PT_EMP.ADDR_ID fk
077 *        &#064;Column(name="WAGE")
078 *        protected Float hourlyWage;
079 *
080 *        public PartTimeEmployee() {}
081 *
082 *        public Float getHourlyWage() { ... }
083 *        public void setHourlyWage(Float wage) { ... }
084 *    }
085 * </pre>
086 *
087 * @see AttributeOverride
088 * @see AssociationOverride
089 * @since Java Persistence 1.0
090 */
091@Documented
092@Target({TYPE})
093@Retention(RUNTIME)
094public @interface MappedSuperclass {
095}