KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > persistence > MappedSuperclass


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package javax.persistence;
24
25 import java.lang.annotation.Target JavaDoc;
26 import java.lang.annotation.Retention JavaDoc;
27 import static java.lang.annotation.ElementType.TYPE JavaDoc;
28 import static java.lang.annotation.RetentionPolicy.RUNTIME JavaDoc;
29
30 /**
31  * Designates a class whose mapping information is applied
32  * to the entities that inherit from it. A mapped superclass
33  * has no separate table defined for it.
34  *
35  * <p> A class designated with the <code>MappedSuperclass</code>
36  * annotation can be mapped in the same way as an entity except that the
37  * mappings will apply only to its subclasses since no table
38  * exists for the mapped superclass itself. When applied to the
39  * subclasses the inherited mappings will apply in the context
40  * of the subclass tables. Mapping information may be overridden
41  * in such subclasses by using the {@link AttributeOverride} and
42  * {@link AssociationOverride} annotations or corresponding XML elements.
43  *
44  * <pre>
45  * Example: Concrete class as a mapped superclass
46  *
47  * &#064;MappedSuperclass
48  * public class Employee {
49  *
50  * &#064;Id protected Integer empId;
51  * &#064;Version protected Integer version;
52  * &#064;ManyToOne &#064;JoinColumn(name="ADDR")
53  * protected Address address;
54  *
55  * public Integer getEmpId() { ... }
56  * public void setEmpId(Integer id) { ... }
57  * public Address getAddress() { ... }
58  * public void setAddress(Address addr) { ... }
59  * }
60  *
61  * // Default table is FTEMPLOYEE table
62  * &#064;Entity
63  * public class FTEmployee extends Employee {
64  *
65  * // Inherited empId field mapped to FTEMPLOYEE.EMPID
66  * // Inherited version field mapped to FTEMPLOYEE.VERSION
67  * // Inherited address field mapped to FTEMPLOYEE.ADDR fk
68  *
69  *
70  * // Defaults to FTEMPLOYEE.SALARY
71  *
72  * protected Integer salary;
73  *
74  *
75  * public FTEmployee() {}
76  *
77  *
78  * public Integer getSalary() { ... }
79  *
80  * public void setSalary(Integer salary) { ... }
81  * }
82  *
83  * &#064;Entity &#064;Table(name="PT_EMP")
84  * &#064;AssociationOverride(name="address",
85  *
86  *
87  * joincolumns=&#064;JoinColumn(name="ADDR_ID"))
88  * public class PartTimeEmployee extends Employee {
89  *
90  * // Inherited empId field mapped to PT_EMP.EMPID
91  * // Inherited version field mapped to PT_EMP.VERSION
92  * // address field mapping overridden to PT_EMP.ADDR_ID fk
93  * &#064;Column(name="WAGE")
94  * protected Float hourlyWage;
95  *
96  * public PartTimeEmployee() {}
97  *
98  * public Float getHourlyWage() { ... }
99  * public void setHourlyWage(Float wage) { ... }
100  * }
101  *
102  * Example: Non-entity superclass
103  *
104  * public class Cart {
105  *
106  * // This state is transient
107  * Integer operationCount;
108  *
109  * public Cart() { operationCount = 0; }
110  * public Integer getOperationCount() { return operationCount; }
111  * public void incrementOperationCount() { operationCount++; }
112  * }
113  *
114  * &#064Entity
115  * public class ShoppingCart extends Cart {
116  *
117  * Collection<Item> items = new Vector<Item>();
118  *
119  * public ShoppingCart() { super(); }
120  *
121  *
122  * ...
123  *
124  * &#064OneToMany
125  * public Collection<Item> getItems() { return items; }
126  * public void addItem(Item item) {
127  * items.add(item);
128  * incrementOperationCount();
129  * }
130  * }
131  * </pre>
132  *
133  * @since Java Persistence 1.0
134  */

135 @Target JavaDoc({TYPE})
136 @Retention JavaDoc(RUNTIME)
137
138 public @interface MappedSuperclass {
139 }
140
Popular Tags