ビッグアップデート:
わかりました、私の問題は私が思っていたよりもはるかに複雑です。次のようなテーブルがあります。
Patient:
id
bloodtype
level (FK to level table)
doctor (FK to doctor table)
person (FK to person table)
Doctor:
id
person (FK)
speciality
level (FK to level)
Paramedic:
id
person (FK)
Person:
id
name
surname
Account:
id
login
pass
Level:
id
account (FK)
name (one of: 'patient' , 'paramedic' , 'doctor')
エンティティクラスでは@Inheritance(strategy= InheritanceType.JOINED)
@DiscriminatorColumn(discriminatorType=DiscriminatorType.STRING,name="name")
、クラスLevelで現在使用しています。誰かが元にいるかどうかを確認するには。患者 私は機能を持っています:
public boolean ifPatient(String login) {
account = accountfacade.getByLogin(login);
for (Level l : account.getLevelCollection()) {
if (l instanceof Patient) {
return true;
}
}
return false;
}
今、状況があります: 私は医師としてログインしています。患者を追加したい。私はこのようなものを持っています:
public Doctor findDoctor(String login) {
account = accountfacade.getByLogin(login);
for (Doctor d : doctorfacade.findAll()) {
if (d.getLevel().getAccount().getLogin().equals(login)) {
doctor = d;
return doctor;
}
}
}
@Override
public void addPatient(Account acc, Patient pat, Person per, String login) {
Doctor d = findDoctor(login);
accountfacade.create(acc);
personfacade.create(per);
Patient p = new Patient();
p.setAccount(acc);
p.setBlood(pat.getBlood());
// etc
p.setPerson(per);
d.getPatientCollection().add(p);
acc.getLevelCollection().add(p);
}
しかし、うまくいきません。Account テーブルの主キーの重複値 (しかし、私はTableGenerator
... を使用します) や、フィールド Account の NULL 値など、常に完全に奇妙なエラーが発生しますが、INSERT INTO Doctor の場合 (どのように?! 新しい患者を作成していますが、医師ではありません...)。私は今完全に迷っているので、私にとって最も重要なことはInheritanceType.JOINED
、この場合に実際に使用できるかどうかを知ることです.