-->
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.  [ 3 posts ] 
Author Message
 Post subject: Using Component for 1:0..1 Relationship
PostPosted: Thu Nov 30, 2006 11:31 am 
Newbie

Joined: Thu Nov 30, 2006 11:05 am
Posts: 5
Hi,

I'm facing a problem in representing a 1:0..1 relationship.

Classes
There are 2 complex entities(classes) SubscriptionAccount & PaymentPlan having their own set of attributes. Both contain, NULL as well as NOT-NULL attributes. PaymentPlan contains another class, PaymentPlanItem.

The 1:0..1 relationship
The PaymentPlan will exist only if a SubcriptionAccount exists & it cannot exist on its own. Also, PaymentPlan may or, may not be null for a given SubscriptionAccount. Any PaymentPlan can have multiple PaymentPlanItems & again, PaymentPlanItems do not exist on their own.

Implementation
Instead of using the regular <one-to-one> representation of hibernate, I tried using the <component> representation, where a PaymentPlan will get represented as a component in SubscriptionAccount.
The config is done as specified below.

Code:


<class name="SubscriptionAccount" table="SUBSCRIPTION_ACCOUNTS">
    <id name="subscriptionAccountID" column="SUBSCRIPTION_ACCOUNT_ID" type="MyGUIDType">
      <generator class="MyGUIDGenerator"/>
    </id>
    <property column="CUSTOMER_ID" name="customerID" not-null="true" />
    <property column="OFFER_LISTING_ID" name="offerListingID" not-null="true" />
    <component name="paymentPlan" class="PaymentPlan" lazy="false" insert="true" update="true">
      <property name="useGiftCertificateFlag" column="USE_GIFT_CERTIFICATE_FLAG"
        type="yes_no" not-null="true" insert="true" update="true"/>
     <property name="chargeAnyInstrumentFlag" column="CHARGE_ANY_INSTRUMENT_FLAG"
        type="yes_no" not-null="true" insert="true" update="true"/>
     <property name="paymentPlanGeneratorID" column="PAYMENT_PLAN_GENERATOR_ID"
        not-null="false" insert="true" update="true"/>
     <set cascade="all" inverse="false" lazy="true" name="paymentPlanItems" table="PAYMENT_PLAN_ITEMS"
       access="property"  outer-join="true">
          <key column="SUBSCRIPTION_ACCOUNT_ID"/>
          <composite-element class="PaymentPlanItem">
            <property access="property" column="PAYMENT_INSTRUMENT_ID" insert="true" name="paymentInstrumentID" not-null="false" type="string" unique="false" update="true"/>
            <property access="property" column="PAYMENT_PLAN_ITEM_PRECEDENCE" insert="true" name="paymentPlanItemPrecedence" not-null="false" type="int" unique="false" update="true"/>
          </composite-element>
      </set>
    </component>



The domain classes as created as regular straightforward classes with getters and setters.

Questions

When i checked the logs the table SUBSCRIPTION_ACCOUNT was getting created with the columns ChargeAnyInstrument , useGiftCertificate as NOT NULL, which is not the expected behavior for my business model.
I expect the chargeAnyInstrumentFlag, useGiftCertificate or the PaymentPlanItems to be created only when a PaymentPlan is created & not for every instance creation of SubscriptionAccount.

In such case, Can I represent my required 1:0..1 relationship using a component or, going with a 1:0..1 is a must?

Summarising everything, can i represent a 1:0..1 with a component ? (or) can my component be null, whereas my component elements aren't ?

I would really really appreciate if someone can help me by answering my questions. A big thanks in advance

thanks,
Sriram


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 30, 2006 11:42 am 
Beginner
Beginner

Joined: Thu Aug 24, 2006 6:01 am
Posts: 49
Location: sophia-antipolis, France
in your mapping for these two columns, you have specified "not-null=true", so it seems logical that that is how they were created.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 30, 2006 11:49 am 
Newbie

Joined: Thu Nov 30, 2006 11:05 am
Posts: 5
Right. Agreed. Does that mean i cannot use a component for this scenario ?


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

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.