Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7550601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:15:15+00:00 2026-05-30T10:15:15+00:00

I am working on a project with hibernate. I got these two files: Persoon.java

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T10:15:17+00:00Added an answer on May 30, 2026 at 10:15 am

    I generally discourage people from using inheritance/polymorphism in Hibernate and this is a prime example why. What added value are you getting from creating this inheritance that outweighs the complexity it generates? Wouldn’t it be easier to just have one entity for Person and one for Patient, and make Patient contain a person, i.e have a M-1 relationship with a person?

    Keep it simple, especially with Hibernate. Relational databases are not meant to handle inheritance, they are meant to handle relationships so why force it into something it’s not meant for?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a java project full of Hibernate (3.3.1) mapping files that have
I am a Java programmer and was working on a project using Hibernate and
I am working on a project which uses Java,MySql,Struts2 MVC and Hibernate. I tried
My first project with Hibernate/JPA and Play!, I've got a menu that once working,
i've been working on a project in java+maven+spring+hibernate and i wanted to automatically assign
I'm working on a project where we use Hibernate and JBoss 5.1. We need
A project I am working on uses Spring 2.5 & JPA with Hibernate as
I am working in a project that's work with N Hibernate. Due to performance
I'm currently working on a project that makes use of Seam/Hibernate (JPA) on MySQL.
I am working on a project using Spring 3.0 and Hibernate 3.x which requires

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.