I was able to get this to work when I separated out the collections. In the
sample code I sent out in the previous posting, I changed Root so that it
has both a collection of A and a collection of SubA. The database had to be
modified, because the SUBA table needed a rootid column like the A table.
Castor wouldn't set up the SQL to look into the A table to get the rootid
for the SubA object. This kind of makes sense, although it increases (and
duplicates) the amount of data in the database.
So, is this the right way to do it? This seems awkward and painful,
especially if you have a wide and/or deep inheritance structure.
Thanks,
jwc
-----Original Message-----
From: Cherney John-CJC030
Sent: Tuesday, December 30, 2003 10:57 AM
To: '[EMAIL PROTECTED]'
Subject: Mapping a collections field to an mapped object
I'm running into a problem with mapping a collection to an object I already
have mapped. I want this collection to contain a particular object or any of
its subclasses (also mapped in the mapping file and in the database).
When I read the object out of the database, it is a collection of the type
of the superclass. That makes sense, because that is type specified in the
mapping file. The superclass has a type field, and I can use that type to
determine the proper type of the class, but when I try to read it out of the
database, I get "org.exolab.castor.jdo.PersistenceException: Requested to
load/fetch an object of type test.SubA, where persistent storage returned an
object of type class test.A" where A is the superclass and SubA is the
subclass.
Does this mean that my object that contains the collection is going to have
to have a collection for each type of subclass?
I am attaching the source code, sql and xml files, the generated output, and
a class diagram of the source code.
Thanks,
jwc
-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-dev