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 * References name of a column in the SELECT clause of a SQL query - 019 * i.e., column alias, if applicable. Scalar result types can be 020 * included in the query result by specifying this annotation in 021 * the metadata. 022 * <p> 023 * <pre> 024 * 025 * Example: 026 * Query q = em.createNativeQuery( 027 * "SELECT o.id AS order_id, " + 028 * "o.quantity AS order_quantity, " + 029 * "o.item AS order_item, " + 030 * "i.name AS item_name, " + 031 * "FROM Order o, Item i " + 032 * "WHERE (order_quantity > 25) AND (order_item = i.id)", 033 * "OrderResults"); 034 * 035 * @SqlResultSetMapping(name="OrderResults", 036 * entities={ 037 * @EntityResult(entityClass=com.acme.Order.class, fields={ 038 * @FieldResult(name="id", column="order_id"), 039 * @FieldResult(name="quantity", column="order_quantity"), 040 * @FieldResult(name="item", column="order_item")})}, 041 * columns={ 042 * @ColumnResult(name="item_name")} 043 * ) 044 * </pre> 045 * 046 * @see SqlResultSetMapping 047 * @since Java Persistence 1.0 048 */ 049@Target({}) 050@Retention(RUNTIME) 051public @interface ColumnResult { 052 053 /** 054 * (Required) The name of a column in the SELECT clause of a SQL query 055 */ 056 String name(); 057 058 /** 059 * (Optional) The Java type to which the column type is to be mapped. 060 */ 061 Class type() default void.class; 062}