I am working on a project with hibernate. I got these two files:
Persoon.java
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@DiscriminatorColumn(name = "PROJ_TYPE")
@Table(name = "PROJECT")
public class Persoon {
@Id
@GeneratedValue
protected int persoonsnummer;
protected String voornaam;
protected String achternaam;
protected String adres;
protected String geboortedatum;
protected String telefoonnummer;
protected String titel;
// Getters and setters ommited for brevity
}
Patient.java
@Entity
@DiscriminatorValue("P")
@Table(name="PATIENT")
public class Patient extends Persoon implements Serializable {
protected String allergieen;
protected String bijzonderheden;
// Getters and setters ommited for brevity
}
And Test.java to fill the tables:
public class Test {
public static void main(String[] args) {
// get a session
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
// Start a tx
session.beginTransaction();
// create a person
Persoon i = new Persoon();
i.setVoornaam("Henk");
i.setAchternaam("Oliebol");
i.setAdres("1234AA Rotterdam");
i.setGeboortedatum("10-10-1990");
i.setTelefoonnummer("012345678");
i.setTitel("Patient");
session.save(i);
// create a patient
Patient p = new Patient();
p.setAllergieen("geen");
p.setBijzonderheden("geen");
session.save(p);// create another car
// commit the tx,
// so that it will be visible in the db
session.getTransaction().commit();
}
}
I want patient to inherit persoon, what is the way of solving this?
I.e. After making a persoon, I want to connect patient to persoon.