• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Paul Clapham
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • Carey Brown
  • Stephan van Hulst
  • Frits Walraven
  • fred rosenberger
  • salvin francis

Doubt on table design and Hibernate mapping

Ranch Hand
Posts: 229
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
    Bookmark Topic Watch Topic
  • New Topic