我有这样的基本实体Employee。
@Entity
@Table(name="EMPLOYEE")
@Inheritance(strategy=InheritanceType.JOINED)
@DiscriminatorColumn(name='EMP_TYPE', discriminatorType=DiscriminatorType.STRING)
public class Employee implements Serializable {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="id")
private Long id;
private String e_name;
还有另一个扩展了Employee的ActiveEmployee实体。
@Entity
@Table(name = "ACTIVE_EMPLOYEE")
@PrimaryKeyJoinColumn("id")
@DiscriminatorValue("ACTIVE")
public class ActiveEmployee extends Employee {
private int e_salary;
private int e_experience;
@ToString.Exclude
@ManyToOne
@JoinColumn(name='SCHEDULES')
private Schedules schedules;
我正在尝试为此系统构建搜索功能。我正在尝试通过活动表的表中的列之一来搜索/过滤雇员(我正在雇员表中搜索)。
这是我尝试过的方法。
public Specification<Employee> getByScheduleCode(String value) {
return (root, cb, query) -> {
Root<ActiveEmployee> activeE = cb.treat(root, ActiveEmployee.class);
Join<ActiveEmployee, Schedules> activeSchedJoin = activeE.join("schedules", JoinType.INNER);
return cb.and(cb.equal(activeSchedJoin.get("code"), value));
};
}
即使使用(cb.treat(root,ActiveEmployee.class),即使出现以下错误。
org.hibernate.QueryException: could not resolve property: schedules of com.myproject.entity.Employee
很显然,即使在使用(cb.treat(root,ActiveEmployee.class)之后,仍在基本Employee表而不是ActiveEmployee表中查看schedules属性。>
我知道我可以直接在ActiveEmployee表中搜索。但是我正在使用的功能要求我从Employee表中过滤结果。
我在这里想念什么吗?
我有这样的基本实体Employee。 @Entity @Table(name =“ EMPLOYEE”)@Inheritance(strategy = InheritanceType.JOINED)@DiscriminatorColumn(name ='EMP_TYPE',discriminatorType = DiscriminatorType ....
根据休眠documentation: