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 to map the SELECT
25 * clause of a SQL query to an entity result.
26 *
27 * <p>If this annotation is used, the SQL statement should select
28 * all of the columns that are mapped to the entity object.
29 * This should include foreign key columns to related entities.
30 * The results obtained when insufficient data is available
31 * are undefined.
32 *
33 * <pre>
34 * Example:
35 *
36 * Query q = em.createNativeQuery(
37 * "SELECT o.id, o.quantity, o.item, i.id, i.name, i.description "+
38 * "FROM Order o, Item i " +
39 * "WHERE (o.quantity > 25) AND (o.item = i.id)",
40 * "OrderItemResults");
41 * @SqlResultSetMapping(name="OrderItemResults",
42 * entities={
43 * @EntityResult(entityClass=com.acme.Order.class),
44 * @EntityResult(entityClass=com.acme.Item.class)
45 * })
46 * </pre>
47 *
48 * @see SqlResultSetMapping
49 *
50 * @since 1.0
51 */
52 @Target({})
53 @Retention(RUNTIME)
54 public @interface EntityResult {
55
56 /** The class of the result. */
57 Class entityClass();
58
59 /**
60 * Maps the columns specified in the SELECT list of the
61 * query to the properties or fields of the entity class.
62 */
63 FieldResult[] fields() default {};
64
65 /**
66 * Specifies the column name (or alias) of the column in
67 * the SELECT list that is used to determine the type of
68 * the entity instance.
69 */
70 String discriminatorColumn() default "";
71 }
72