2015-06-15 95 views
0

我無法啓動服務器,因爲它抱怨在查詢中找不到繼承的屬性。繼承類型加入JPA - 在Spring中查詢屬性JPA

爲便於討論,我已經建立了一個類層次結構是這樣的:

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數據/ 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); 

我的問題是,因爲我m試圖將其移動到繼承模型(加入),我如何引用註釋查詢中的繼承屬性?

(注意,該酒店是在BaseContent公共的getter/setter私有可見)

謝謝

回答

0

啊woops,我忘了@Entity註釋在超...

作品了。