-->
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: Address class vs Member/Customer/Employee Mapping Problem
PostPosted: Fri Sep 08, 2006 3:47 pm 
Regular
Regular

Joined: Fri Feb 03, 2006 5:28 pm
Posts: 73
Location: Québec, QC, Canada
Hi folks,

let's say I have a class Member, Customer and Employee and a Class Address

All address are to be saved in a single table while member has its table, customer its table as well as Employee.

Each of these class may have one or many address.

since the IdAddress isn't defined in Member/Customer/Employee, and there is a possibility of having to Id of value 1 (IdMember = 1 and IdCustomer = 1)
how should I map everything in the .hbm.xml files?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 09, 2006 1:45 am 
Senior
Senior

Joined: Mon Aug 21, 2006 9:18 am
Posts: 179
Are Member,Customer, and Employee all inheriting from a base class?

If I understand you scenario, it sounds like you need to use the joined-subclass (Table Per Subclass Strategy...see http://www.hibernate.org/hib_docs/nhibernate/html/inheritance.html) for your Member, Customer, and Employee tables which will meet your need of having the same ID across all three tables.

In your Adress table, you'd have an PersonId (or whatever you want to call it) that would allow the one-to-many, person-to-addresses setup.

Am I understanding your question?[/url]

_________________
If this helped...please remember to rate it!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 22, 2006 9:43 am 
Newbie

Joined: Wed Nov 22, 2006 9:15 am
Posts: 1
Solved problem for brother-classes user, company which each one has a single address using a many-to-one-relation. Methinks one can expand this to a many-to-many-relation.

Attention: You have to manually insert/update the Address-object before the User resp. Company.
Code:
class Address {.. };
class User { ... Address address ... };
class Company { ... Address address ... };

Mapping for class User is:
Code:
<class name="User">
...
<many-to-one name="address" class="Address" column="address_id" unique="false" not-null="false" />
</many-to-one>
...
</class>

Mapping for class Company is same. Mapping for class Address is
Code:
<class name="Address">
<id> ..</id>
...
</class>

(no back-link in address mapping).


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.