-->
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.  [ 3 posts ] 
Author Message
 Post subject: Inheriting class with Non persistence fields
PostPosted: Tue Nov 22, 2005 3:28 pm 
Newbie

Joined: Mon Nov 21, 2005 5:21 pm
Posts: 6
I have a generic CONTENT table in the Database that holds all the images and PDFs and other binary content. There is a CONTENTTYPE table to distinguish different types but ContentTypeID is not FK in CONTENT table. Instead, ContentTypeID is used as a PK of a table called PERSON_CONTENT to associate different types of content for a given person.

In Java implementation, ImageContent, PDFContent extends Content class. These children classes have additional identifiers of their own but all of the new properties in the children are totally Non-Persistent fields.

Given this DB schema, My approach was to go with a Table per class heirarchy and create a Content.hbm.xml with discriminator column as contentType ( this column is unfortunately not in Content table. So I tried using discriminator formula instead).

My content.hbm.xml looks like this:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

<hibernate-mapping>

<class
name="com.xxx.Content"
table="CONTENT" discriminator-value="?(dont know what to put here)"
>
<id
name="contentId"
type="java.lang.Long"
column="CONTENT_ID"
>
<generator class="sequence">
<param name="sequence">TABLESEQ</param>
</generator>
</id>
<discriminator formula="SELECT content_type_id FROM content_type"/>
<property
name="title"
type="java.lang.String"
column="TITLE"
length="400"
/>
<subclass
name="ImageContentBean"
discriminator-value="11">
</subclass>

<subclass
name="PDFContentBean"
discriminator-value="12">
</subclass>
</class>
</hibernate-mapping>
[/color]
With this, I am getting the exception that reads as follows:

Caused by: org.xml.sax.SAXParseException: The content of element type "class" must match "(meta*,subselect?,cache?,synchronize*,(id|composite-id),discriminator?,(version|timestamp)?,(property|many-to-one|one-to-one|component|dynamic-component|properties|any|map|set|list|bag|idbag|array|primitive-array|query-list)*,((join*,subclass*)|joined-subclass*|union-subclass*),loader?,sql-insert?,sql-update?,sql-delete?,filter*)".
at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
at org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source)
...

Here are my questions:
1. Because the fields in the children class are not persistent, Do I still need to specify <subclass> in Content.hbm.xml?

2. What should be the discriminator value for the Content table? There is no unique type for the parent one. It can be any one from the children. ( Marked by Question_mark in the hbm.xml file above)

3. Do I require a separate mapping for each <subclass> item listed in Content.hbm.xml?

4.

Can anyone point me in the right direction?

Thanks in advance


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 23, 2005 3:50 am 
Expert
Expert

Joined: Mon Jul 04, 2005 5:19 pm
Posts: 720
what happens if you change

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


to

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


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 23, 2005 11:44 am 
Newbie

Joined: Mon Nov 21, 2005 5:21 pm
Posts: 6
I was able to resolve the exception by putting the subclass tag after the association tags.
But I am still getting classcastException when I do

PDFContentBean pdfCb = (PDFContentBean)content.getContent();

Do I have to tweak anything else in my setting?


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