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.Repeatable; 013import java.lang.annotation.Retention; 014import java.lang.annotation.Target; 015 016import static java.lang.annotation.ElementType.TYPE; 017import static java.lang.annotation.RetentionPolicy.RUNTIME; 018 019/** 020 * Specifies the mapping of the result of a native SQL query. 021 * <p> 022 * <pre> 023 * Example: 024 * 025 * Query q = em.createNativeQuery( 026 * "SELECT o.id AS order_id, " + 027 * "o.quantity AS order_quantity, " + 028 * "o.item AS order_item, " + 029 * "i.name AS item_name, " + 030 * "FROM Order o, Item i " + 031 * "WHERE (order_quantity > 25) AND (order_item = i.id)", 032 * "OrderResults"); 033 * 034 * @SqlResultSetMapping(name="OrderResults", 035 * entities={ 036 * @EntityResult(entityClass=com.acme.Order.class, fields={ 037 * @FieldResult(name="id", column="order_id"), 038 * @FieldResult(name="quantity", column="order_quantity"), 039 * @FieldResult(name="item", column="order_item")})}, 040 * columns={ 041 * @ColumnResult(name="item_name")} 042 * ) 043 * </pre> 044 * 045 * @since Java Persistence 1.0 046 */ 047@Target({TYPE}) 048@Retention(RUNTIME) 049@Repeatable(SqlResultSetMappings.class) 050public @interface SqlResultSetMapping { 051 /** 052 * The name given to the result set mapping, and used to refer to it in the methods of the {@link Query} 053 * API. 054 * 055 * @return name 056 */ 057 String name(); 058 059 /** 060 * Specifies the result set mapping to entities. 061 * 062 * @return entities 063 */ 064 EntityResult[] entities() default {}; 065 066 /** 067 * Specifies the result set mapping constructor references 068 * 069 * @return classes 070 */ 071 ConstructorResult[] classes() default {}; 072 073 /** 074 * Specifies the result set mapping to scalar values. 075 * 076 * @return cols 077 */ 078 ColumnResult[] columns() default {}; 079}