1 /*
2  * Copyright (c) 2008, 2019 Oracle and/or its affiliates. All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v. 2.0 which is available at
6  * http://www.eclipse.org/legal/epl-2.0,
7  * or the Eclipse Distribution License v. 1.0 which is available at
8  * http://www.eclipse.org/org/documents/edl-v10.php.
9  *
10  * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
11  */

12
13 // Contributors:
14 //     Petros Splinakis - 2.2
15 //     Linda DeMichiel - 2.1
16 //     Linda DeMichiel - 2.0
17
18 package javax.persistence;
19
20 import java.lang.annotation.Repeatable;
21 import java.lang.annotation.Target;
22 import java.lang.annotation.Retention;
23 import static java.lang.annotation.ElementType.TYPE;
24 import static java.lang.annotation.RetentionPolicy.RUNTIME;
25
26 /** 
27  * Specifies the mapping of the result of a native SQL query or stored 
28  * procedure.
29  *
30  * <pre>
31  *    Example:
32  *
33  *    Query q = em.createNativeQuery(
34  *        "SELECT o.id AS order_id, " +
35  *            "o.quantity AS order_quantity, " +
36  *            "o.item AS order_item, " +
37  *            "i.name AS item_name, " +
38  *        "FROM Order o, Item i " +
39  *        "WHERE (order_quantity &gt; 25) AND (order_item = i.id)",
40  *    "OrderResults");
41  *    
42  *    &#064;SqlResultSetMapping(name="OrderResults"
43  *        entities={ 
44  *            &#064;EntityResult(entityClass=com.acme.Order.class, fields={
45  *                &#064;FieldResult(name="id", column="order_id"),
46  *                &#064;FieldResult(name="quantity", column="order_quantity"), 
47  *                &#064;FieldResult(name="item", column="order_item")})},
48  *        columns={
49  *            &#064;ColumnResult(name="item_name")}
50  *    )
51  * </pre>
52  *
53  * @see Query
54  * @see StoredProcedureQuery
55  * @see NamedNativeQuery
56  * @see NamedStoredProcedureQuery
57  *
58  * @since 1.0
59  */

60 @Repeatable(SqlResultSetMappings.class)
61 @Target({TYPE}) 
62 @Retention(RUNTIME)
63 public @interface SqlResultSetMapping { 
64
65     /** 
66      * The name given to the result set mapping, and used to refer 
67      * to it in the methods of the {@link Query} and 
68      * {@link StoredProcedureQuery} APIs.
69      */

70     String name(); 
71
72     /** Specifies the result set mapping to entities. */
73     EntityResult[] entities() default {};
74
75     /** 
76      * Specifies the result set mapping to constructors. 
77      * @since 2.1
78      */

79     ConstructorResult[] classes() default {};
80
81     /** Specifies the result set mapping to scalar values. */
82     ColumnResult[] columns() default {};
83 }
84