我想知道是否有任何优雅的方式,过滤雇员实体以下的数据模型。
因此,如果我需要过滤“姓名”,“hourlyRate”和“薪金”,我不能使用jpa规范,我需要写一个原始的sql
模型化
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@Entity
@DiscriminatorColumn(name = "EMP_TYPE")
JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXISTING_PROPERTY, property = "EMP_TYPE", visible = true)
@JsonSubTypes({
@JsonSubTypes.Type(value = FullTimeEmployee .class, name = "F"),
@JsonSubTypes.Type(value = PartTimeEmployee .class, name = "P"),
})
public class Employee {
@Id
@GeneratedValue
private long id;
private String name;
}
类型类别
@Entity
@DiscriminatorValue("F")
public class FullTimeEmployee extends Employee {
private int salary;
.............
}
@Entity
@DiscriminatorValue("P")
public class PartTimeEmployee extends Employee {
private int hourlyRate;
.............
}
'SHOW TABLES'
[EMPLOYEE, PUBLIC]
'SHOW COLUMNS from EMPLOYEE'
[EMP_TYPE, VARCHAR(31), NO, , NULL]
[ID, BIGINT(19), NO, PRI, NULL]
[NAME, VARCHAR(255), YES, , NULL]
[HOURLYRATE, INTEGER(10), YES, , NULL]
[SALARY, INTEGER(10), YES, , NULL]
1条答案
按热度按时间rqmkfv5c1#
您可以编写如下所示的HQL查询: