-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: One-to-one in conjunction with joined-subclass
PostPosted: Tue Aug 03, 2004 11:36 am 
Newbie

Joined: Mon Jul 19, 2004 3:34 pm
Posts: 4
I'd greatly appreciate mapping advice on this; despite re-readings of the Hibernate literature and forums, I'm not grokking this one. It's very simple, but apparently so am I.

I have a Loan class with properties of type PrimaryApplicant and CoApplicant. Both PrimaryApplicant and CoApplicant extend Applicant. (primaryApplicant is required, coApplicant is optional.)

Now the question: how do I use joined-subclass (my preference for subclass mappings) so that my applicants are all in the APPLICANT table, with its own primary key, yet my LOAN table references PRIMARY_APPLICANT and CO_APPLICANT properly (or vice versa)?

I've tried various combinations, and I either get LOAN to properly reference PRIMARY and CO via proper foreign keys, or I get PRIMARY and CO to properly reference APPLICANT via APPLICANT_ID. But I can't get those at the same time!

I want to make sure that when I delete or update a loan, all related APPLICANT/CO/PRIMARY is cleaned up properly.

Here's my attempted mapping, which I know is wrong.
Code:
    <class name="Loan" table="LOAN">
   <id name="loanId" type="string">
       <column name="LOAN_ID" length="10"/>
       <generator class="assigned"/>
   </id>

   <one-to-one name="primaryApplicant" class="PrimaryApplicant"/>
   <one-to-one name="coApplicant" class="CoApplicant"/>
   ...   
    </class>

    <class name="Applicant" table="APPLICANT">
   <id name="applicantId" column="APPLICANT_ID" type="integer" unsaved-value="-1">
       <generator class="sequence">
      <param name="sequence">APPLICANT_ID_SEQ</param>
       </generator>
   </id>
   ...
    </class>

    <joined-subclass name="PrimaryApplicant" extends="Applicant" table="PRIMARY_APPLICANT">
   <key column="APPLICANT_ID"/>
   ...
    </joined-subclass>

    <joined-subclass name="CoApplicant" extends="Applicant" table="CO_APPLICANT">
   <key column="APPLICANT_ID"/>
   ...
    </joined-subclass>


Here's the table structure I'd like to see - my goals is to keep APPLICANT "free" of loan references, although that's not critical. It could be used for non-loan purposes, so my intention was to put references to LOAN only in CO and PRIMARY.

Code:
TABLE LOAN (
    LOAN_ID  PRIMARY_KEY
    CO_APP_ID references CO_APPLICANT
    PRIMARY_APP_ID references PRIMARY_APPLICANT
    ...
)

TABLE APPLICANT (
    APPLICANT_ID  PRIMARY_KEY
    ...
)

TABLE PRIMARY_APPLICANT (
    LOAN_ID PRIMARY_KEY references LOAN
    APPLICANT_ID references APPLICANT
    ...
)

TABLE CO_APPLICANT (
    LOAN_ID PRIMARY_KEY references LOAN
    APPLICANT_ID references APPLICANT
    ...
)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.