-->
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: Polymorphic association with table per subclass inheritence
PostPosted: Thu Apr 29, 2010 1:03 pm 
Newbie

Joined: Thu Apr 29, 2010 11:52 am
Posts: 3
I'm not seeing the 2cd level cache hit for a List in a base class and I'm wondering if the subclasses inherit the many-to-one link setup in the base class. The object I start with is actually a subtype (not shown here) of the ManagedObject class. I can see the top level object (ManagedObject) hit in the cache but the children nodes associated with the object are retrieved each time from the database.

Here is the top level class.

Code:
<?xml version="1.0"?>
<!-- $Id: ManagedObject.hbm.xml,v 1.13 2008/12/15 17:12:19 sudharshan Exp $ -->
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping package="com.adventnet.nms.topodb">

   <class name="ManagedObject"
         table="ManagedObject"
         dynamic-insert="true"
         dynamic-update="true"
         select-before-update="true"
         discriminator-value="ManagedObject">
   <cache usage="read-write"/>
   <id name="moid" column="MOID">
      <generator class="increment"/>
   </id>
   <discriminator column="DISCRIMINATOR" type="string" length="30"/>
   <natural-id>
      <property name="name"  type="string" column="NAME" not-null="true" length="255" />
   </natural-id>
...skipped properties..
   <list name="children" inverse="true" lazy="true" >
      <key column="PARENTID" on-delete="cascade"/>
      <list-index column="MOID"/>
      <one-to-many class="ManagedObject" />
   </list>
       
   <many-to-one name="parentId" column="PARENTID" class="ManagedObject"/>
   </class>
</hibernate-mapping>



Here is the subclass.
Does it need to also setup the many-to-one link or is doing it at the base class sufficient?

Code:
<?xml version="1.0"?>
<!-- $Id: TopoObject.hbm.xml,v 1.3 2008/11/24 11:48:33 sudharshan Exp $ -->
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping package="com.adventnet.nms.topodb">

<subclass name="TopoObject"  extends="ManagedObject"
      dynamic-insert="true"
      dynamic-update="true"
      select-before-update="true"
      discriminator-value="TopoObject">
   <join table="TopoObject" fetch="select">
   <key on-delete="cascade">
   <column name="MOID"/>
   </key>
    <property
        name="baseMibs"
        type="string"
        column="BASEMIBS"
        length="100"/>
...skipped properties..
    <property
        name="writeCommunity"
        type="string"
        column="WRITECOMMUNITY"
        length="100"/>
   </join>
   </subclass>
</hibernate-mapping>
   


Top
 Profile  
 
 Post subject: Re: Polymorphic association with table per subclass inheritence
PostPosted: Tue May 04, 2010 10:58 am 
Newbie

Joined: Thu Apr 29, 2010 11:52 am
Posts: 3
I discovered that the subclass does inherit from the parent as one would expect. The issue of why the children were not loaded into cache was because the cache-usage clause was omitted from the children association in the parent class.

<list name="children" inverse="true" lazy="true" >
<cache-usage="read-write"/>
<key column="PARENTID" on-delete="cascade"/>
<list-index column="MOID"/>
<one-to-many class="ManagedObject" />
</list>


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.