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.Retention; 013import java.lang.annotation.Target; 014 015import static java.lang.annotation.RetentionPolicy.RUNTIME; 016 017/** 018 * Used to map the SELECT clause of a SQL query to an entity result. If this annotation is used, the SQL 019 * statement should select all of the columns that are mapped to the entity object. This should include 020 * foreign key columns to related entities. The results obtained when insufficient data is available are 021 * undefined. 022 * <p> 023 * <pre> 024 * Example: 025 * 026 * Query q = em.createNativeQuery( 027 * "SELECT o.id, o.quantity, o.item, i.id, i.name, i.description "+ 028 * "FROM Order o, Item i " + 029 * "WHERE (o.quantity > 25) AND (o.item = i.id)", 030 * "OrderItemResults"); 031 * @SqlResultSetMapping(name="OrderItemResults", 032 * entities={ 033 * @EntityResult(entityClass=com.acme.Order.class), 034 * @EntityResult(entityClass=com.acme.Item.class) 035 * }) 036 * </pre> 037 * 038 * @see SqlResultSetMapping 039 * @since Java Persistence 1.0 040 */ 041@Target({}) 042@Retention(RUNTIME) 043public @interface EntityResult { 044 045 /** 046 * The class of the result. 047 * 048 * @return entity class 049 */ 050 Class entityClass(); 051 052 /** 053 * Maps the columns specified in the SELECT list of the query to the properties or fields of the entity 054 * class. 055 * 056 * @return fields 057 */ 058 FieldResult[] fields() default {}; 059 060 /** 061 * Specifies the column name (or alias) of the column in the SELECT list that is used to determine the 062 * type of the entity instance. 063 * 064 * @return disc col 065 */ 066 String discriminatorColumn() default ""; 067}