-->
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.  [ 2 posts ] 
Author Message
 Post subject: unidirectional one-to-one can have null id?
PostPosted: Mon Jun 12, 2006 12:22 pm 
Beginner
Beginner

Joined: Fri Mar 12, 2004 1:02 pm
Posts: 23
Hi,

I have a one-to-one relationship using a unidirectional many-to-one w/FK constraint mapping and I was wondering if I can allow null values for the FK. For example, I have a one-to-one relationship between Customer and Account (where Customer knows Account but not vice-versa). Sometimes the business rule allows a Customer to exist without an Account (for accounts pending) so I need the flexibility of having null values for accountIds in the customer table. How can I allow this null value on the FK. The way I have it set up now, I get a FK constraint... below is my mapping:

Code:
<hibernate-mapping>

    <class
        name="com.test.domain.Customer"
        table="CUSTOMER">

        <id name="customerId" type="long">
            <column name="CUSTOMER_ID" not-null="true"/>
            <generator class="native"/>
        </id>

        .....

        <many-to-one
            name="account"
            class="com.test.domain.Account"
            column="ACCOUNT_ID"
            cascade="all"
            unique="true"/>   
    </class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 12, 2006 2:08 pm 
Beginner
Beginner

Joined: Fri Mar 12, 2004 1:02 pm
Posts: 23
BTW, I've also tried to include the attribute not-null="false" into the many-to-one mapping (see below) but still get the same result. Is there another way of defining a one-to-one that allows a null constraint on the FK?

Code:

        <many-to-one
            name="account"
            class="com.test.domain.Account"
            column="ACCOUNT_ID"
            cascade="all"
            unique="true"
            not-null="false"/>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.