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 // Linda DeMichiel - 2.1
15 // Linda DeMichiel - 2.0
16
17 package javax.persistence;
18
19 import java.lang.annotation.Target;
20 import java.lang.annotation.Retention;
21 import static java.lang.annotation.RetentionPolicy.RUNTIME;
22
23 /**
24 * Used in conjunction with the {@link SqlResultSetMapping} annotation or
25 * {@link ConstructorResult} annotation to map a column of the SELECT
26 * list of a SQL query.
27 *
28 * <p> The <code>name</code> element references the name of a column in the SELECT list
29 * — i.e., column alias, if applicable. Scalar result types can be
30 * included in the query result by specifying this annotation in
31 * the metadata.
32 *
33 * <pre>
34 *
35 * Example:
36 * Query q = em.createNativeQuery(
37 * "SELECT o.id AS order_id, " +
38 * "o.quantity AS order_quantity, " +
39 * "o.item AS order_item, " +
40 * "i.name AS item_name, " +
41 * "FROM Order o, Item i " +
42 * "WHERE (order_quantity > 25) AND (order_item = i.id)",
43 * "OrderResults");
44 *
45 * @SqlResultSetMapping(name="OrderResults",
46 * entities={
47 * @EntityResult(entityClass=com.acme.Order.class, fields={
48 * @FieldResult(name="id", column="order_id"),
49 * @FieldResult(name="quantity", column="order_quantity"),
50 * @FieldResult(name="item", column="order_item")})},
51 * columns={
52 * @ColumnResult(name="item_name")}
53 * )
54 * </pre>
55 *
56 * @see SqlResultSetMapping
57 *
58 * @since 1.0
59 */
60 @Target({})
61 @Retention(RUNTIME)
62
63 public @interface ColumnResult {
64
65 /** (Required) The name of a column in the SELECT clause of a SQL query */
66 String name();
67
68 /**
69 * (Optional) The Java type to which the column type is to be mapped.
70 * If the <code>type</code> element is not specified, the default JDBC type
71 * mapping for the column will be used.
72 * @since 2.1
73 */
74 Class type() default void.class;
75 }
76