很多时候我在我的实体中使用@Formula。但总是这是一个简单的查询或带参数的存储过程,我可以从表中提取。现在我需要从相关对象中使用一些属性。但是当我尝试从DB获取对象时,我看到异常。请参阅下面的示例
@Entity
@Table(name = "MINISTRY")
public class Ministry {
@Id
@Column(name = "ID")
private Long id;
@Column(name = "NAME")
private String name;
// unnecessary code
}
@Entity
@Table(name = "DEPARTMENT")
public class Department {
@Id
@Column(name = "ID")
private Long id;
@Column(name = "DEP_NAME")
private String departmentName;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "MINISTRY_ID")
private Ministry ministry;
// unnecessary code
}
@Entity
@Table(name = "EMPLOYEE")
public class Employee {
@Id
@Column(name = "ID")
private Long id;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "DEPARTMENT_ID")
private Department department;
@Formula("test_package.calc_something(department.ministry.id)")
private BigDecimal someMetric;
// unnecessary code
}
我应该如何在@Formula中使用实体道具。 我不想写像
这样的东西select d.ministry.id from Department d ...