基于其他两个实体映射的 JPA 实体映射更新
2022-09-03 15:52:42
不确定这是否可行,但尝试根据其他两个实体映射和下面的实体映射来映射哪个相关。WorkflowInstancePlayer player
WorkActionClass
WorkflowInstance
public class Action implements Serializable {
@Id
private Long action_id;
@ManyToOne
@JoinColumn(name = "work_action_class_id", referencedColumnName = "work_action_class_id")
private WorkActionClass workActionClass;
@ManyToOne
@JoinColumn(name = "workflow_instance_id", referencedColumnName = "workflow_instance_id")
private WorkflowInstance workflowInstance;
UPDATE: How can I map to a WorkflowInstancePlayer player?????
@ManyToOne
@JoinColumns( {
@JoinColumn(name = "workflow_instance_id", referencedColumnName = "workflow_instance_id", insertable = false, updatable = false),
@JoinColumn(name = "workActionClass.role_class_id", referencedColumnName = "role_class_id", insertable = false, updatable = false)
})
private WorkflowInstancePlayer player;
workflowInstancePlayer是基于和派生的,但实际上是上面映射的一个属性workflow_instance_id
role_class_id
role_class_id
workActionClass
(workActionClass.role_class_id)
public class WorkflowInstancePlayer implements Serializable {
@Id
private WorkflowInstance workflowInstance;
@Id
private RoleClass roleClass;
@ManyToOne
@JoinColumn(name = "badge", referencedColumnName = "badge")
private Employee employee;
public class WorkActionClass implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "trx_seq")
private Long work_action_class_id;
@ManyToOne
@JoinColumn(name = "role_class_id")
private RoleClass roleClass;
示例数据包括:
Action
------
Id = 10
work_action_class_id = 7
workflow_instance_id = 2
WorkActionClass
---------------
Id = 7
role_name = reviewer
role_class_id = 3
WorkflowInstancePlayer
----------------------
workflow_instance_id = 2
role_class_id = 3
badge = 111222
因此,在操作实体中,我将知道工作流实例播放器是具有 Id 111222的员工,而无需实际将徽章存储在“操作”表中。
更新
根据弗拉德的帖子,我将其调整为
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumnsOrFormulas({
@JoinColumnOrFormula(formula=@JoinFormula(value="(SELECT a.role_class_id FROM (Use Table Name not Entity Name here) a WHERE a.work_action_class_id = work_action_class_id)", referencedColumnName="role_class_id")),
@JoinColumnOrFormula(column = @JoinColumn(name="workflow_instance_id", referencedColumnName="workflow_instance_id"))
})