JPA TABLE_PER_CLASS继承:如何只选择SELECT超类条目? [英] JPA TABLE_PER_CLASS inheritance: How to only SELECT superclass entries?
问题描述
我正在使用EclipseLink作为JPA提供程序。此外,我正在使用以下TABLE_PER_CLASS继承结构
I'm using EclipseLink as the JPA provider. Further I'm using the following TABLE_PER_CLASS inheritance structure
@javax.persistence.Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@NamedQueries({
@NamedQuery(name=Parent.QUERY_FIND_ALL, query="SELECT p FROM Parent p")
})
public class Parent {
// the class code follows here
}
@javax.persistence.Entity
@NamedQueries({
@NamedQuery(name=Child.QUERY_FIND_ALL, query="SELECT c FROM Child c")
})
public class Child extends Parent {
// the class code follows here
}
现在的问题是我只想接收父类的条目。但是使用命名查询SELECT p FROM Parent p,也会返回子表中的所有条目。
The problem now is that I only want to receive entries of the parent class. But with the named query "SELECT p FROM Parent p" also all entries from the child table are returned.
选择或查找代码如下:
public List findWithNamedQuery(String query) {
return em.createNamedQuery(query).getResultList();
}
因此查询就是SELECT p FROM Parent p。
Thereby query is i.e. the "SELECT p FROM Parent p".
我怎样才能真正收到父条目而不是这个继承层次结构的所有条目?
How can I only receive really the parent entries and not all entries of this inheritacne hierarchy?
简而言之:怎么能我保留所有子条目不变,只返回父条目?
In short: How can I leave all child entries untouched, and return only the parent entries?
编辑1:
我正在使用EclipseLink 2.0.1,但每次我通过类型表达式尝试axtavt的解决方案时,都会出现以下错误:
EDIT 1:
I'm using EclipseLink 2.0.1, but every time I try axtavt's solution via the type expression, I get the following error:
"Invalid Type Expression on [my.domain.Parent]. The class does not have a descriptor, or a descriptor that does not use inheritance or uses a ClassExctractor for inheritance".
我已经更新到EclipseLink的最新稳定版本2.1.1,但它没有解决问题。
I've updated also to the latest stable version 2.1.1 of EclipseLink, but it doesn't resolve the issue.
推荐答案
Type表达式与TABLE_PER_CLASS继承结合在EclipseLink 2.1.1下不起作用,这似乎是是一个错误。
The Type expression in combination with TABLE_PER_CLASS inheritance doesn' t work under EclipseLink 2.1.1, this seems to be a bug.
这篇关于JPA TABLE_PER_CLASS继承:如何只选择SELECT超类条目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!