私はこのモデルを持っています。2つのエンティティだけです。1つはキー用の埋め込み可能なエンティティで、もう1つはそのキーがidフィールドとして存在するエンティティです。
「誰かの名前の人のすべての機能を私に与えてください」の「ID5の人のすべての機能を私に与えてください」のような簡単なクエリを書く方法を知りたいです。
その埋め込み可能なキーがあるときにこれらの情報にアクセスする方法がわかりません...
コードの周りにたくさんのものを書き直さなければならないので、モデルを書き直すのをためらっています。
その関連付けテーブルからいくつかのものを削除するにはどうすればよいですか?その問題を攻撃するためにどの「方法」を取るべきか、私は本当に知りません。
ヒントをありがとう
@Entity
@Table(name = "PERSON")
public class Person {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "person_id")
private Long id;
@Column(name = "name", unique = true)
private String name;
// .. getters and setters
@Entity
@Table(name = "FUNC")
public class Function {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "function_id")
private Long id;
@Column(name = "name")
private String name;
// .. getters and setter
@Embeddable
public class PersonFunctionPK {
@Column(name = "person_id")
private Long personId;
@Column(name = "function_id")
private Long functionId;
public PersonFunctionPK() {
}
PersonFunctionPK(Long personId, Long functionId) {
this.personId = personId;
this.functionId = functionId;
}
// .. getters and setter
@Entity
@Table(name = "PERSON_FUNC")
public class PersonFunction {
@EmbeddedId
protected PersonFunctionPK personFunctionPK;
public PersonFunction() {}
public PersonFunction(PersonFunctionPK personFunctionPK) {
this.personFunctionPK = personFunctionPK;
}
public PersonFunction(Long personId, Long functionId) {
this.personFunctionPK = new PersonFunctionPK(personId, functionId);
}
// .. getters and setter for personFunctionPK