小编Joa*_*rto的帖子

Spring Data JPA规范继承

我有三个实体,如下所示:

@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@DiscriminatorColumn(name = "type")
public abstract class Employee {
    @Id
    protected Long id;
    ...
}

@Entity
public class FullTimeEmployee extends Employee {
    protected Integer salary;
    ...
}

@Entity
public class PartTimeEmployee extends Employee {
    protected Float hourlyWage;
}
Run Code Online (Sandbox Code Playgroud)

我尝试使用Spring Data Specification查询,如下所示:

我的Spring数据托管存储库:

@Repository
public interface EmployeeRepository<T extends Employee> extends JpaRepository<T, Long> {
    Page<T> findAll(Specification<T> specification, Pageable pageable);
}
Run Code Online (Sandbox Code Playgroud)

还有我的样品控制器

@Controller
public class MyController {
    private final EmployeeRepository employeeRepository;

    @Autowired
    public MyController(EmployeeRepository employeeRepository) {
        this.employeeRepository = employeeRepository; …
Run Code Online (Sandbox Code Playgroud)

java spring jpa spring-data spring-data-jpa

3
推荐指数
1
解决办法
1297
查看次数

标签 统计

java ×1

jpa ×1

spring ×1

spring-data ×1

spring-data-jpa ×1