classlink error java,java – EclipseLink:对MappedSuperclass的查询失败

我的应用程序是一个销售鱼类,水族馆等的商店.我想根据销售数量获得所有项目中的前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提供商.

标签:java,jpa,eclipselink

来源: https://codeday.me/bug/20190730/1582072.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值