• Post Reply Bookmark Topic Watch Topic
  • New Topic

Doubt on table design and Hibernate mapping  RSS feed

Edmund Yong
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Suppose that I want to represent a loan application. This loan application must have one main applicant, and zero or more joint applications. Obviously, the Java class representation would be like this:

public class LoanApplication {
Borrower mainApplicant;
List jointApplicants;

The joinApplicants list will contain instances of Borrower. The mainApplicant and jointApplicants instances can only exist within the life time of the LoanApplication instance. That is, the loan application is composed of the main applicant and joint applicants, and without the loan application, there won't be a main applicant or any joint applicants.

How do I model that in Hibernate mapping as well as the database table?

For database table, I have LOAN_APPLICATION table below to represent a loan. Its primary key is APPLICATION_ID.

The BORROWER table will contain main applicant and joint applicants records. It will have APPLICATION_ID to denote the parent table, and a BORROWER_ID (which is the primary key) to distinctly identify the main and joint applicants.

create table LOAN_APPLICATION (

create table BORROWER (

The MAIN_APPLICANT_ID in the LOAN_APPLICATION table will reference the BORROWER_ID in BORROWER table for the main applicant. Since BORROWER_ID is primary key, the MAIN_APPLICANT_ID will always link to exactly one record.

For joint borrowers, both the BORROWER_ID and APPLICATION_ID in BORROWER table will be used.

Is this design OK? If yes, how would the mapping look like?

Thanks in advance.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!