I will be using the Postgres database, and I will post here a SQL script to create the tables and the needed records. If you have any doubts about how to set up your application (e.g. persistence.xml, libraries, build path) check out the older posts about this subjects. I will post here just the needed data to this post.

The @SecondaryTable annotation “tells” to the JPA that there is another table with some data of the Person class.

The parameter pkJoinColumns of the @SecondaryTable annotation it is used to indicate which column the JPA will use as relationship. We did not indicate any field in the @SecondaryTable annotation to specify the relationship between the tables person and health_care; the JPA by default will match the person table ID with the health_care id ([person]id == [health_care]id).

In the @Column annotation of the “companyName” attribute, we notify the JPA in which table it will find attribute value through the “table” parameter.

I will write bellow, a code that will find our record Person in the database: