-->
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.  [ 1 post ] 
Author Message
 Post subject: inheritance mapping problem using Abstract class parrent
PostPosted: Thu Feb 17, 2011 4:36 pm 
Newbie

Joined: Thu Feb 17, 2011 1:34 pm
Posts: 1
Hello forum ,
I have trouble with hibernate3 mapping , please help me .I have to link the following objects : AbstractContent (abstract parent) Document and Image .
I have tables
site(id as PK ) ,
abstractContent(id as PK and FK from site table),
document(id as FK from abstractContent table),
image (id as FK from abstractContent).

I have java classes
Site (Site HAS A AbstractContent)
AbstractContent
Document (IS A AbstractContent)
Image(IS A AbstractContent)
I use Table per subclass: using a discriminator inheritance mapping strategy here is the AbstractContent.hbm.xml
Code:
<hibernate-mapping package="org.cbsean.entity">
<typedef class="org.cbsean.entity.URLType" name="URLType"/>
<class abstract="true" name="AbstractContent" table="Content">
    <id name="id">
        <generator class="foreign">
            <param name="property">rootPageContent</param>
            </generator>
    </id>
    <discriminator column="contentType"/>
    <property name="url" not-null="true" type="URLType"/>
    <property name="altAttributeValue"/>
    <property name="titleAttributeValue"/>
    <property name="indexDate" not-null="true" type="timestamp" update="false"/>
    <subclass discriminator-value="document" name="Document">
        <join table="Document">
            <key column="id" foreign-key="true"/>
            <property name="documentTitle"/>
        </join>
    </subclass>
    <subclass discriminator-value="image" name="Image">
        <join table="Image">
            <key column="id" foreign-key="true"/>
            <property name="fileName"/>
        </join>
    </subclass>
</class>

here is Site.hbm.xml
Code:
<hibernate-mapping package="org.cbsean.entity">
  <class name="Site">
    <id name="id" >
      <generator class="native" />
    </id>
    <property name="host"/>
    <property name="submitDate" not-null="true" type="timestamp" update="false"/>
    <property name="nextIndexDate" type="timestamp"/>
    <property name="reindexInterval"/>
    <property name="blocked"/>
    <property name="blockReason"/>
    <property name="crawlingDepth"/>
    <property name="indexedPageCount"/>
    <property name="score"/>
     <one-to-one class="AbstractContent" name="rootPageContent"/>
  </class>
</hibernate-mapping>

I do site.setContent(content); template.save(site);
No data is inserted into content , document | image tables


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.