I've seen people use many-to-one mappings to represent one-to-one relationships. I've also read this in a book by Gavin King and on articles.
For example, if a customer can have exactly one shipping address, and a shipping address can belong to only one customer, the mapping is given as:
<class name="Customer" table="CUSTOMERS">
...
<many-to-one name="shippingAddress"
class="Address"
column="SHIPPING_ADDRESS_ID"
cascade="save-update"
unique="true"/>
...
</class>
The book reasons as (quoting it):
"You don't care what's on the target side of the association, so you can treat it like a to-one association without the many part."
My question is, why use many-to-one
and not one-to-one
? What is it about a one-to-one
that makes it a less desirable option to many-to-one
?
Thanks.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…