Forums Register Login

Doubt on table design and Hibernate mapping

+Pie Number of slices to send: Send
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 (
APPLICATION_ID NUMBER(16),
MAIN_APPLICANT_ID NUMBER(16),
...
);

create table BORROWER (
BORROWER_ID NUMBER(16),
APPLICATION_ID NUMBER(16),
...
);

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.
Yup, yup, yup. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 845 times.
Similar Threads
How to start JPA
Hibernate Mapping problem because no primary key in database
Hibernate Bags & Composite IDs
Problem with joining of two tables with Hibernate
UML questions, need answers
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 05:40:25.