ER図は次のとおりです。で別のテーブル内の1つの主キーに一つのテーブルに2つの外部キーをマップする方法休止状態
@Entity
@Table(name = "state_flows")
public class StateFlowEntity {
private int id;
private StateMachineEntity stateMachine;
private StateEntity currentState;
private StateEntity nextState;
@ManyToOne
@JoinColumn(name = "current_state", referencedColumnName = "id",
insertable = false, updatable = false)
public StateEntity getCurrentState() {
return currentState;
}
@ManyToOne
@JoinColumn(name = "next_state", referencedColumnName = "id",
insertable = false, updatable = false)
public StateEntity getNextState() {
return nextState;
}
@ManyToOne
@JoinColumn(name = "machine_id", referencedColumnName = "id",
insertable = false, updatable = false)
public StateMachineEntity getStateMachine() {
return stateMachine;
}
//setters and getters
= ========================================== ================
@Entity
@Table(name = "states")
public class StateEntity {
public enum NodeType {
EVENT
};
private int id;
private String name;
private NodeType nodeType;
private String nodeId;
private int ratio;
private int missingRatio;
private String nodeDetail;
private Set<StateFlowEntity> nextStateFlows = new HashSet<StateFlowEntity>();
private Set<StateFlowEntity> currentStateFlows = new HashSet<StateFlowEntity>();
@OneToMany(cascade = CascadeType.ALL, mappedBy = "nextState",
targetEntity = StateEntity.class)
public Set<StateFlowEntity> getNextStateFlows() {
return nextStateFlows;
}
@OneToMany(cascade = CascadeType.ALL, mappedBy = "currentState",
targetEntity = StateEntity.class)
public Set<StateFlowEntity> getCurrentStateFlows() {
return currentStateFlows;
}
@Column(name = "node_type", nullable = false,
columnDefinition = "ENUM('EVENT') default 'EVENT'")
@Enumerated(EnumType.STRING)
private NodeType getNodeType() {
return nodeType;
}
//setter and getters
=========================== ======================================== ===========
@Entity
@Table(name = "state_machines")
public class StateMachineEntity {
private int id;
private String name;
private String description;
private int initialState;
private int combinational;
private Set<StateFlowEntity> machineId = new HashSet<StateFlowEntity>();
private Set<InstanceEntity> instances = new HashSet<InstanceEntity>();
@OneToMany(cascade = CascadeType.ALL, mappedBy = "stateMachine")
public Set<StateFlowEntity> getMachineId() {
return machineId;
}
@OneToMany(cascade = CascadeType.ALL, mappedBy = "stateMachine")
public Set<InstanceEntity> getInstances() {
return instances;
}
//setters and getters
================================ =============================
が、そのエラーの下に私を与える:データベース接続をintializingで
エラー。 org.hibernate.AnnotationException:mappedByは、未知のターゲットエンティティプロパティを参照:私はやっているところcom.test.entity.StateEntity.currentStateFlows
でcom.test.orm.entity.StateEntity.currentState私は、休止状態に新しいです違う?
ここで 'StateEntity'にtargetEntityを使用してもよろしいですか?コレクション型 'StateEntity'は' nextState'と 'currentState'の名前付き属性を公開しませんので、両方の場合にこのエラーが発生する可能性があります。 – Naros