-->
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: Why is this unidirectional relation unusual ?
PostPosted: Thu Feb 17, 2011 10:34 am 
Newbie

Joined: Wed Mar 10, 2010 12:03 pm
Posts: 7
Hi guys



Quoting from the manual.

Quote:
8.2.3. One-to-many

A unidirectional one-to-many association on a foreign key is an unusual case, and is not recommended.
Code:
<class name="Person">
    <id name="id" column="personId">
        <generator class="native"/>
    </id>
    <set name="addresses">
        <key column="personId"
            not-null="true"/>
        <one-to-many class="Address"/>
    </set>
</class>

<class name="Address">
    <id name="id" column="addressId">
        <generator class="native"/>
    </id>
</class>


You should instead use a join table for this kind of association.


I would like to manipulate Addresses from the Person POJO not other way around and not by using join table.

exmaple:
Person.addAddress(address1);
Person.addAddress(address2);
Person.addAddress(address3);

and not
Address.setPerson(person);


I'm wondering why is this case unusual (by the manual).

Regards

Armando


Top
 Profile  
 
 Post subject: Re: Why is this unidirectional relation unusual ?
PostPosted: Thu Feb 17, 2011 11:17 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
For me One-to-Many unidirectional relation as explained in 8.2.3 is unusual and not recommended because it doesn't fit any UML-specification and because it isn't a true unidirectional relation.

Unidirectional implies that the right side of the relation shouldn't know anything about the left side,
so from this point of view it makes absolutely no sense to restrict the left side cardinality to One:
you don't should have control about that, if the relation really should be unidirectional.

So the unique true unidirectional relations are
Many-to-one (explained in 8.3.2. ) and Many-to-many (explained in 8.3.4.).


Top
 Profile  
 
 Post subject: Re: Why is this unidirectional relation unusual ?
PostPosted: Fri Feb 18, 2011 3:07 am 
Newbie

Joined: Wed Mar 10, 2010 12:03 pm
Posts: 7
Thank you for your reply.

... theory vs. practice situation ...

regards

Armando


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.