-->
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.  [ 6 posts ] 
Author Message
 Post subject: Advice for daealing with inheritance correctly
PostPosted: Mon May 03, 2004 9:21 am 
Regular
Regular

Joined: Mon Oct 06, 2003 1:59 am
Posts: 52
Hi Folks,

which kind of inheritance is the best way to map the
Accountability Analyis Pattern?

Here we have:


Image


As you can see Person and Organiation are both Parties. This it correct to map the using <many-to-any> and many-to-one in (abstract) Party class.

Here what I did:

Code:
<?xml version="1.0"?>

<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
    <class
        name="de.grob.portal.domain.model.Accountablity"
        table="ACCOUNTABILITIES"
        proxy="de.grob.portal.domain.model.Accountablity"
        dynamic-update="false"
        dynamic-insert="false"
    >

        <id
            name="accountId"
            column="ACCOUNT_ID"
            type="long"
        >
            <generator class="native">
            </generator>
        </id>

        <set
            name="timePeriods"
            lazy="true"
            inverse="false"
            cascade="none"
            sort="unsorted"
        >

              <key
                  column="TIME_PERIOD_ID"
              />

              <one-to-many
                  class="de.grob.portal.domain.model.TimePeriod"
              />
        </set>

        <set
            name="types"
            lazy="false"
            inverse="false"
            cascade="none"
            sort="unsorted"
        >

              <key
                  column="ACCOUNT_TYPE_ID"
              />

              <one-to-many
                  class="de.grob.portal.domain.model.AccountablityType"
              />
        </set>

       <set name="comissioners" lazy="true" inverse="false" cascade="none" sort="unsorted">
      <key column="COMISSIONER_ID"/>
      <many-to-any
        id-type="string">
        <!-- Person, Organization, Post -->         
        <column name="COMISSIONER_TYPE"/>
        <column name="COMISSIONER_ID"/>         
      </many-to-any>
   </set>
   <set name="responsibles" lazy="true" inverse="false" cascade="none" sort="unsorted">
      <key column="RESPONSIBILITY_ID"/>
      <many-to-any       
        id-type="string">
        <!-- Person, Organization, Post -->   
        <column name="RESPONSIBILITY_TYPE"/>   
        <column name="RESPONSIBILITY_ID"/>         
      </many-to-any>
   </set>

    </class>

</hibernate-mapping>

<?xml version="1.0"?>

<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
    <class
        name="de.grob.portal.domain.model.Person"
        table="PERSONS"
        proxy="de.grob.portal.domain.model.Person"
        dynamic-update="false"
        dynamic-insert="false"
    >

        <id
            name="personId"
            column="PERSON_ID"
            type="long"
        >
            <generator class="native">
            </generator>
        </id>

   
        <many-to-one
            name="comissioner"
            class="de.grob.portal.domain.model.Accountablity"
            cascade="none"
            outer-join="auto"
            update="true"
            insert="true"
            column="ACCOUNT_COMMISSIONER_FK"
        />

     

        <one-to-one
            name="responsbile"
            class="de.grob.portal.domain.model.Accountablity"
            cascade="none"
            outer-join="auto"
            constrained="true"
        />

   

    </class>   

</hibernate-mapping>


Or is it petter to use a different kind of mapping. As you can see Parties should be interchanable in Accountablity class.

Is there a common rule when to choose one of the thre inheritance mapping strategies?

Thx a lot!!!!

Bye
Toby

_________________
"Wisest of the Maia was Ol


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 03, 2004 7:30 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Why not using subclass (type as discriminator) instead of the bad and slow *-to-any

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 04, 2004 11:29 am 
Regular
Regular

Joined: Mon Oct 06, 2003 1:59 am
Posts: 52
emmanuel wrote:
Why not using subclass (type as discriminator) instead of the bad and slow *-to-any


I already meditated about this solution. But this breaks the rational mantra IMHO, if not please let me know.

As you can image a Person as different attributes as a Organization or a Post. As all of this types are Parties the table per hierachy will end up in a suop of entities. Did I misread the docs? Using a discriminator and subclass may force me to use a single soup table, right?

Any chance to use joined-subclass ?

Why is *-to-any so bad? Could you please provide more technial details ;) ?

_________________
"Wisest of the Maia was Ol


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 05, 2004 12:30 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
*-to-any break every single mantra hinduists have ever think of ;-)

what do you mean by a "soup of entities"? Yes you table will keep the whole hierarchy and you'll face null values in your rows.
You can check joined-subclass for mapping a hierarchy having lots of different properties in subclasses.

*-to_any will need an extra query to load the any object, it's hard to use by third party applications and it breaks the relational model.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 06, 2004 9:38 am 
Regular
Regular

Joined: Mon Oct 06, 2003 1:59 am
Posts: 52
emmanuel wrote:
*-to-any break every single mantra hinduists have ever think of ;-)

what do you mean by a "soup of entities"? Yes you table will keep the whole hierarchy and you'll face null values in your rows.
You can check joined-subclass for mapping a hierarchy having lots of different properties in subclasses.


Okay. It try it know with joined-subclasses. With soup I mean "keep the whole hierarchy" in one table. From OO perspectivce this is not so clean ;) I mean there is some sort of gap between mapped objectes and database entities....

As far as I can see hibernate provides a good solution with joinded-subclasses.

So as far as I understand the docs the abstract class can be used as normaly one-to-many mapping within every kind of collection and therefore threaten transparently like every other mapped domain model pojo, right?

Thx
Toby

_________________
"Wisest of the Maia was Ol


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 06, 2004 11:19 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
For a relational perspective, what you call a entity soup is perfectly valid

_________________
Emmanuel


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