-->
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: Inheritance mapping question
PostPosted: Fri Jan 21, 2005 2:26 pm 
Beginner
Beginner

Joined: Tue Feb 17, 2004 11:20 am
Posts: 28
Hi,

I'm quite new to hibernate, I was using toplink a lot. and now I'm trying to upgrade our project to Hibernate. I read the doc, and H in Action.

most of the mapping is easy to convert but this one gives me many problems...


I have the following inherintence.

Person (abstract) -> LegalPerson (abstract) - Organization
- Manufacturer
- Dealer

also Person has a reference to one legalPerson.
it's not self reference. as it happends on the person level.

I have tables for each entity (Person, LegalPerson, Org, Man.., Dealer..)
in the Person table there is a foreign key to the LegalPerson table
Person has a column named (legalperson_id)

when a use session load to get for example a manufacturer it works perfectly if there is no legalperson attached to the entity but if it has one. it throws an exception ->
Cannot instantiate abstract class or interface: at.oeamtc.edds.model.LegalPerson

it's obvious as the LegalPerson is abstract. and hibernate shold use the same mechnism to find out what kind of contrete class to instanciate that it's using when just load the class itself.

can someone point me to some direction how I shold change my mapping to get the desired result...



Hibernate version:
2.1.7
Mapping documents:

<class name="at.oeamtc.edds.model.Person" table="Person" polymorphism="implicit">
<id name="id" type="long" column="id">
<generator class="sequence">
<param name="sequence">seq_person</param>
</generator>
</id>
<property name="name" column="name" type="string"/>
<many-to-one name="country" column="country_id" foreign-key="fk_person_country_id" class="at.oeamtc.edds.model.Country" cascade="none"/>
<many-to-one name="legalPerson" column="legalperson_id" foreign-key="fk_person_legalperson_id" cascade="save-update"/>
<joined-subclass name="at.oeamtc.edds.model.LegalPerson" table="legalPerson" extends="at.oeamtc.edds.model.Person">
<key column="id"/>
<property name="defaultPwd" column="defaultpwd" type="string"/>
<property name="url" column="url" type="string"/>
<property name="image" column="image" type="string"/>
<property name="toYourHands" column="toyourhands" type="string"/>
<many-to-one name="address" column="address_id" foreign-key="fk_legalperson_address_id" class="at.oeamtc.edds.model.Address" cascade="all" unique="true"/>
<joined-subclass name="at.oeamtc.edds.model.Manufacturer" table="manufacturer">
<key column="id"/>
<many-to-one name="organization" column="organisation_id" foreign-key="fk_manufacturer_org_id" class="at.oeamtc.edds.model.Organization" cascade="none"/>
</joined-subclass>
<joined-subclass name="at.oeamtc.edds.model.Organization" table="org">
<key column="id"/>
</joined-subclass>
</joined-subclass>
</class>


Name and version of the database you are using:
Oracle 9i


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 28, 2005 1:16 pm 
Regular
Regular

Joined: Tue Jun 22, 2004 8:01 pm
Posts: 106
Location: PowderTown, Utah, USA
You should be mapping the sublcasses with the <joined-subclass> tag. Since you have a table-per-subclass, you won't need to use the <subclass> and a discriminator column. Check the documentation:

http://www.hibernate.org/hib_docs/refer ... nheritance


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.