-->
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: One-To-One mapping between several classes
PostPosted: Sun Feb 06, 2005 6:29 pm 
Newbie

Joined: Sun Feb 06, 2005 12:33 am
Posts: 1
Hi,

I am using Hibernate 2.1.7 and here are some of my persistent objects:

Company
User
PurchaseOrder
Address
.... and so on.

I want to create one-to-one mappings between:

Company and Address
User and Address
PurchaseOrder and Address

After reading page 37 of the Hibernate documentation, I successfully created this mapping between Company and Address (where the id value of Address comes from Company's id). But, as mentioned on page 37, the way to make this one-to-one mapping work is to make Address "aware" of Company, by having a property which points to the parent Company.

So here comes my problem:

Since I would like to have a one-to-one mapping between Address and the two other entity types (User and PurchaseOrder), how can I make Address "aware" of those three types simultaneously. I thought about creating a base class for all the parent objects of Address, so that Address would point to only one base type, but this does not seem to work.

Furthermore, does it really make a good design to have an entity like Address have to be "aware" of it's parent object?

Anybody have any ideas about this?
Thanks in advance,
Chris


Top
 Profile  
 
 Post subject: OO model
PostPosted: Mon Feb 07, 2005 7:03 pm 
Newbie

Joined: Tue Dec 14, 2004 2:57 pm
Posts: 12
What would your Java code look like in the Address class? How does it reference it's parent? Is it just an Object? That doesn't make much sense from an OO perspective (anything can have an address? even an address?)

If you want to you can set everything up with a common class, like you said, but I wonder, for the odd time you really need that back reference, would it not be easier to just create the query then (with HQL)?

--Ryan


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.