-->
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.  [ 4 posts ] 
Author Message
 Post subject: mapping help
PostPosted: Thu May 25, 2006 4:09 pm 
Newbie

Joined: Fri Jul 01, 2005 4:36 pm
Posts: 11
Location: US
Hibernate 3.1.3

I have only ever used Table-Per-Concrete-Class mapping strategies, but now need to map more complicated stuff.

I have 2 kinds of Accounts: Company-Accounts and Person-Accounts

Company-Accounts are associated with one or more Companies, each of which then are associated with one or more Persons.

Person-Accounts have no Company at all, and are associated directly with one and only one Person.

I have a discriminator in Account thats tells me what type of Account it is.

I think its some combination of Table-Per-Class-Hierarchy and Table-Per-Subclass, or perhaps some usage of implicit polymorphism.

I am using surrogate identity keys throughout. DB is db2 v8 if that matters.

Any help appreciated.

aj


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 25, 2006 11:45 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
That's plain old table per subclass. You don't even have to make use of the discriminator (though you can if you like). A given account is going to have a row in either the company accounts table, or the person accounts table, but not both. The table per subclass section in the refdocs (9.1.2) fits your description perfectly.

The fact that the company accounts class includes a collection of person accounts is incidental to the polymorphism issue.

If you have trouble mapping this, post again.

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 26, 2006 9:08 am 
Newbie

Joined: Fri Jul 01, 2005 4:36 pm
Posts: 11
Location: US
Thankyou very much for your help. I'm almost there.

I have
<joined-subclass name="CorporateAccount" table="company">
<key column="account_id"/>
.....
and
<joined-subclass name="PersonAccount" table="person">
<key column="account_id"/>
.....
in my Account.hbm.xml

So this means that I have to create separate CorporateAccount.java & PersonAccount.java classes, as well as CorporateAccount.hbm.xml &
PersonAccount.hbm.xml files?

A particular account can be associated w/ many CorporateAccounts,
but only one PersonAccount. Do I need to map this somehow? Does
the <joined-subclass> above for CorporateAccount need an embedded <set> or something? Is one-to-many inherent in <joined-subclass>?

What does the CorporateAccount.java contain? A Set of Companies?
How about PersonAccount.java? A single Person?

thanks tenwit


tenwit wrote:
That's plain old table per subclass. You don't even have to make use of the discriminator (though you can if you like). A given account is going to have a row in either the company accounts table, or the person accounts table, but not both. The table per subclass section in the refdocs (9.1.2) fits your description perfectly.

The fact that the company accounts class includes a collection of person accounts is incidental to the polymorphism issue.

If you have trouble mapping this, post again.


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 28, 2006 6:16 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
allenjhbn wrote:
So this means that I have to create separate CorporateAccount.java & PersonAccount.java classes, as well as CorporateAccount.hbm.xml &
PersonAccount.hbm.xml files?

You need sepate java files for all classes, yes. You don't need separate .hbm.xml files, the <joined-subclass> mapping is the hbm definition of those classes.

allenjhbn wrote:
A particular account can be associated w/ many CorporateAccounts,
but only one PersonAccount. Do I need to map this somehow? Does
the <joined-subclass> above for CorporateAccount need an embedded <set> or something? Is one-to-many inherent in <joined-subclass>?

Absolutely you need to map the association as a <set>. If both kinds of account have the relationship, put it in the Account mapping, otherwise put it in the correct subclass. <joined-subclass> is not a relationship, it's a polymorphism operator, so there is no one-to-many, or indeed any-to-any relationship implied. When a class A is "related to" another class B via <joined-subclass>, that means that an object of class A is an object of class B: it's not related to a different object of class B.

_________________
Code tags are your friend. Know them and use them.


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