![](/img/trans.png)
[英]How to get parent entity with all child entities and child entities of children in Spring/JPA/Hibernate with Lombok
[英]spring jpa - get all entities with discriminatorType
我有兩個繼承自ExerciceFramework
實體的實體,我怎樣才能獲得所有帶有他們的 discriminatorType professionType
類型的ExerciseFramework
框架, findAll()
function 不返回此屬性
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "professionType", discriminatorType = DiscriminatorType.STRING)
public class ExerciseFrameworkEntity implements Serializable { }
@Entity
@DiscriminatorValue("ETP")
public class Company extends ExerciseFrameworkEntity { }
@Entity
@DiscriminatorValue("ETA")
public class Establishment extends ExerciseFrameworkEntity { }
@Repository
public interface ExerciceFrameworkRepository extends JpaRepository<ExerciseFramework, String> {
}
你可以為你想要的子類型聲明一個新的 Repository 接口。 喜歡:
CompanyRepo extends JpaRepository<Company, String>
當我遇到與您相同的情況時,我只創建了 3 個存儲庫接口,一個用於返回所有類型的基本 class,然后是該接口的 2 個擴展,專門返回子類型。 它很容易被 Generics 控制。 在您的情況下,類似於:
ExerciceFrameworkRepo<T extends ExceriseFrameworkEntity> extends JpaRepository<T, String>
CompanyRepo extends ExerciseRepo<Company>
EstablishmentRepo extends ExerciseRepo<Establishment>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.