我正在使用单表继承策略。我想通过使用鉴别器类型过滤数据库来在数据库中执行搜索。我如何在 JPA 中编写一个函数来执行此操作。
使用 method 定义方法的正常方式findBy...不会产生结果。
这是我的家长课
@Entity
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(
name="Leave_Type",
discriminatorType=DiscriminatorType.STRING
)
public class LeaveQuota {
// the fields and the required methods
}
Run Code Online (Sandbox Code Playgroud)
这是两个子实体
@Entity
@DiscriminatorValue("Annual")
public class AnnualLeave extends LeaveQuota {
// the fields and the required methods
}
@Entity
@DiscriminatorValue("Casual")
public class CasualLeave extends LeaveQuota {
// the fields and the required methods
}
Run Code Online (Sandbox Code Playgroud)
我想通过分别过滤年假和休闲假来查询数据库。这意味着当我搜索年假时,应检索鉴别器列中值为“annual”的所有记录。我怎样才能实现这个。提前致谢!
inheritance hibernate single-table-inheritance spring-data-jpa spring-boot