Re: Mapping hierarchy in one table problem
Armin Waibel <[email protected]> Fri, 08 Feb 2008 19:42:34 +0100
| Newsgroups | gmane.comp.jakarta.ojb.user |
|---|---|
| Message-ID | <[email protected]> |
Hi,
which version of OJB do you use?
Schmidt wrote:
> Hi,
>
> I'm facing a hard time trying to fix a problem in my app. Consider the
> floowing class hierarchy:
> class Project {..}
> class ChildProject extends Project {..}
> class GrandChildProject extends ChildProject {..}
>
How do you set the ojbConcreteClass attribute in your java object?
> All these classes are mapped to the same table: PROJECT_TABLE
>
> Here are the mappings:
>
> <class-descriptor table="PROJECT_TABLE" class="br.com.xxx.model.Project">
> <extent-class class-ref="br.com.xxx.model.ChildProject" />
> ...some fields here...
> <field-descriptor name="ojbConcreteClass" column="CLASS_NAME"
> jdbc-type="VARCHAR" />
> </class-descriptor>
>
> <class-descriptor table="PROJECT_TABLE"
> class="br.com.xxx.model.ChildProject">
> <extent-class class-ref="br.com.xxx.model.GrandChildProject" />
> ...some fields here...
> <field-descriptor name="ojbConcreteClass" column="CLASS_NAME"
> jdbc-type="VARCHAR" />
> </class-descriptor>
>
> <class-descriptor table="PROJECT_TABLE"
> class="br.com.xxx.model.GrandChildProject ">
> ...some fields here...
> <field-descriptor name="ojbConcreteClass" column="CLASS_NAME"
> jdbc-type="VARCHAR" />
> </class-descriptor>
>
> Somehow when I search for GrandChildProject objects, OJB returns a
> ChildProject reference. This ends up in a ClassCastException. Is there
> anything wrong in the mappings or strategy used in this example?
The mapping seems ok.
regards,
Armin
>
> Thanks in advance!