我的应用程序是一个销售鱼类,水族馆等的商店.我想根据销售数量获得所有项目中的前10个项目列表.我使用以下类:
@MappedSuperclass
@NamedQueries({
@NamedQuery(name="getTopItems",query="SELECT x FROM FishStoreItem x ORDER BY x.salescnt DESC,x.title DESC")
})
public abstract class FishStoreItem
extends DomainSuperClass implements Serializable {
......
}
问题出在以下异常中:
Exception [EclipseLink-8034] (Eclipse
Persistence Services –
2.0.0.v20091127-r5931): org.eclipse.persistence.exceptions.JPQLException
Exception Description: Error compiling
the query [getTopItems: SELECT x FROM
FishStoreItem x ORDER BY x.salescnt
DESC,x.title DESC]. Unknown entity
type [FishStoreItem].
相同的代码适用于Apache OpenJpa 2.0.0,但在EclipseLink ver 2.1.0,2.0.1,1.0中失败.
附:我已经为Hibernate找到了that解决方案,但我想确保EclipseLink也不可能.
映射的超类不是实体,不允许查询,持久化或与超类关系(参见
Mapped Superclasses).
这在Apache OpenJPA 2.0用户指南中得到了证实:
07001
A mapped superclass is a non-entity
class that can define persistent state
and mapping information for entity
subclasses. Mapped superclasses are
usually abstract. Unlike true
entities,you cannot query a mapped
superclass,pass a mapped superclass
instance to any EntityManager
or
Query methods,or declare a persistent
relation with a mapped superclass
target. You denote a mapped superclass
with the MappedSuperclass
marker
annotation.
…
Note
OpenJPA allows you to query on mapped
superclasses. A query on a mapped
superclass will return all matching
subclass instances. OpenJPA also
allows you to declare relations to
mapped superclass types; however,you
cannot query across these relations.
因此,虽然OpenJPA允许您的查询,但这超出了JPA.不要指望它适用于任何JPA提供商.