【问题标题】:Inheritance Type Joined JPA - query for property in Spring JPA继承类型加入 JPA - 在 Spring JPA 中查询属性
【发布时间】: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


    【解决方案1】:

    哎呀,我忘记了超类上的@Entity 注释...

    现在可以使用了。

    【讨论】:

      猜你喜欢
      • 2016-01-29
      • 2019-03-22
      • 2017-11-23
      • 1970-01-01
      • 1970-01-01
      • 2022-11-23
      • 2011-06-20
      • 1970-01-01
      • 2022-01-10
      相关资源
      最近更新 更多