EntityResult (Java EE 5)

Java EE API


javax.persistence Annotation Type EntityResult


@Target(value={})
@Retention(value=RUNTIME)
public @interface EntityResult

Implements: Annotation
@Target(value={})
@Retention(value=RUNTIME)

引用 SQL 查询的 SELECT 子句中的实体。如果使用此注释,则 SQL 语句应该选择映射到该实体对象的所有列。这应该包括相关实体的外键列。数据不足时返回的结果是不确定的。
示例
   Query q = em.createNativeQuery(
       "SELECT o.id, o.quantity, o.item, i.id, i.name, i.description "+
           "FROM Order o, Item i " +
           "WHERE (o.quantity > 25) AND (o.item = i.id)",
       "OrderItemResults");
   @SqlResultSetMapping(name="OrderItemResults",
       entities={
           @EntityResult(entityClass=com.acme.Order.class),
           @EntityResult(entityClass=com.acme.Item.class)
   })
 
英文文档:

References an entity in the SELECT clause of a SQL query. If this annotation is used, the SQL statement should select all of the columns that are mapped to the entity object. This should include foreign key columns to related entities. The results obtained when insufficient data is available are undefined.

   Example
   Query q = em.createNativeQuery(
       "SELECT o.id, o.quantity, o.item, i.id, i.name, i.description "+
           "FROM Order o, Item i " +
           "WHERE (o.quantity > 25) AND (o.item = i.id)",
       "OrderItemResults");
   @SqlResultSetMapping(name="OrderItemResults",
       entities={
           @EntityResult(entityClass=com.acme.Order.class),
           @EntityResult(entityClass=com.acme.Item.class)
   })
 

Since:
Java Persistence 1.0

Required Element Summary
 Class
 
Optional Element Summary
 String
 FieldResult[]
 

Element Detail

abstract public Class<T> entityClass()
结果类
英文文档:

entityClass

public abstract Class entityClass
The class of the result

abstract public FieldResult[] fields()
将查询的 SELECT 列表中指定的列映射到实体类的属性或字段。
英文文档:

fields

public abstract FieldResult[] fields
Maps the columns specified in the SELECT list of the query to the properties or fields of the entity class.

Default:
{}

abstract public String discriminatorColumn()
指定 SELECT 列表中的列名称(或别名),该名称用于确定实体实例的类型。
英文文档:

discriminatorColumn

public abstract String discriminatorColumn
Specifies the column name (or alias) of the column in the SELECT list that is used to determine the type of the entity instance.

Default:
""


Submit a bug or feature

Copyright 2007 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms.

一看就知道只有菜鸟才干这么无知的事啦。

PS : 未经我党受权你也可自由散发此文档。 如有任何错误请自行修正;若因此而造成任何损失请直接找人民主席,请勿与本人联系。谢谢!