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