java - JPA Entity Mapping which is related based on two other entity mappings -
not sure if possible trying map workflowinstanceplayer player
related based on 2 other entity mappings, workactionclass
, workflowinstance
in entity below.
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 map 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 derived based on workflow_instance_id
, role_class_id
role_class_id
attibute of workactionclass
mapped above (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;
example data be:
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
so in action entity, i'll know workflow instance player employee id 111222 without storing badge in action table.
update
based on vlad's post tweaked
@manytoone(fetch=fetchtype.lazy) @joincolumnsorformulas({ @joincolumnorformula(formula=@joinformula(value="(select a.role_class_id (use table name not entity name here) a.work_action_class_id = work_action_class_id)", referencedcolumnname="role_class_id")), @joincolumnorformula(column = @joincolumn(name="workflow_instance_id", referencedcolumnname="workflow_instance_id")) })
try mapping:
@manytoone @joincolumn( name = "workflow_instance_id", referencedcolumnname = "workflow_instance_id", insertable = false, updatable = false ) private workflowinstance workflowinstance; @manytoone @joincolumnorformula( formula = @joinformula( value="(select a.work_action_class_id workactionclass a.role_class_id = role_class_id)", referencedcolumnname = "work_action_class_id" ) ) private workactionclass workactionclass; @manytoone @joincolumns( { @joincolumn( name = "workflow_instance_id", referencedcolumnname = "workflow_instance_id"), @joincolumn( name = "role_class_id", referencedcolumnname = "role_class_id") }) private workflowinstanceplayer player;
Comments
Post a Comment