【发布时间】:2015-08-31 01:33:27
【问题描述】:
我无法启动我的服务器,因为它抱怨在查询中找不到继承的属性。
出于讨论的目的,我设置了这样的类层次结构:
BaseContent
==============
id
createUser
Category
===============
id
otherProperties
我已经声明了这样的类型:
@Inheritance(strategy = InheritanceType.JOINED)
@Table(name = "base_content")
public class BaseContent {
...
}
和
@Entity
@Table(name="categories")
@Inheritance(strategy = InheritanceType.JOINED)
@PrimaryKeyJoinColumn(name = "base_content_id", referencedColumnName = "id")
public class Category extends BaseContent{
}
注意相关属性都有getter/setter等。
我正在使用 Spring Data/JPA,而我的服务器和 Intellij 都抱怨找不到此查询的继承属性 createUser(以及其他):
@Query("select c from Category c " +
"left join fetch c.createUser " +
"left join fetch c.lastUpdateUser " +
"left join fetch c.galleries g " +
"left join fetch g.media " +
"left join fetch c.parentRelationship pr " +
"left join fetch c.productCategoryRelationships pcr " +
"left join fetch pcr.child " +
"left join fetch c.appliedLayouts l " +
"left join fetch pr.parent " +
"where c.id = ?1")
public Category findById(Long categoryId);
我的问题是,由于我试图将其移至继承模型(已连接),我如何在带注释的查询中引用继承的属性?
(注意该属性是私有可见性,在 BaseContent 中具有公共 getter/setter)
谢谢
【问题讨论】:
标签: spring jpa spring-data-jpa