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

Attachment: castor_test.zip
Description: Binary data

c:\j2sdk1.4.1_02\bin\javaw   -classpath 
"C:\Borland\Together6.1\out\classes\untitled3;C:\Borland\Together6.1\lib\javax.jar;C:\Borland\Together6.1\myprojects\untitled3\castor-0.9.4.3.jar;C:\Borland\Together6.1\myprojects\untitled3\xerces.jar;;C:\Borland\Together6.1\myprojects\untitled3\interclient.jar"
 -Xdebug -Xnoagent -Djava.compiler=NONE 
-Xrunjdwp:transport=dt_shmem,address=javadebug,suspend=y test.TestMain 
[Castor] mapping.xml is not a URL, trying to convert it to a file URL[Castor] Loading 
mapping descriptors from mapping.xmlBegin write...Printing out contents before 
write...   root (test.Root)                A1 (test.A)             A2 (test.SubA)End 
write...Begin read...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        at 
org.exolab.castor.persist.TransactionContext.load(TransactionContext.java:622)       
at org.exolab.castor.persist.QueryResults.fetch(QueryResults.java:229)  at 
org.exolab.castor.jdo.engine.OQLQueryImpl$OQLEnumeration.next(OQLQueryImpl.java:711) 
at 
org.exolab.castor.jdo.engine.OQLQueryImpl$OQLEnumeration.next(OQLQueryImpl.java:684) 
at test.TestMain.getObjectByID(TestMain.java:110)       at 
test.Root.convertA(Root.java:24)     at test.Root.convertAs(Root.java:33)    at 
test.Root.setAs(Root.java:16)        at 
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)        
at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)  
      at java.lang.reflect.Method.invoke(Method.java:324)     at 
org.exolab.castor.persist.FieldMolder.setValue(FieldMolder.java:318) at 
org.exolab.castor.persist.CollectionProxy$ColProxy.close(ClassMolder.java:2980)      
at org.exolab.castor.persist.ClassMolder.load(ClassMolder.java:789)     at 
org.exolab.castor.persist.LockEngine.load(LockEngine.java:359)       at 
org.exolab.castor.persist.TransactionContext.load(TransactionContext.java:649)       
at org.exolab.castor.persist.QueryResults.fetch(QueryResults.java:229)  at 
org.exolab.castor.jdo.engine.OQLQueryImpl$OQLEnumeration.hasMore(OQLQueryImpl.java:641)
      at 
org.exolab.castor.jdo.engine.OQLQueryImpl$OQLEnumeration.hasMore(OQLQueryImpl.java:624)
      at test.TestMain.readRoots(TestMain.java:94)    at 
test.TestMain.read(TestMain.java:82)Printing out contents after read:        root 
(test.Root)                A1 (test.A)     at test.TestMain.run(TestMain.java:43)  at 
test.TestMain.main(TestMain.java:27)java.lang.NullPointerException   at 
test.TestMain.printAs(TestMain.java:130)     at 
test.TestMain.printRoots(TestMain.java:122)  at test.TestMain.read(TestMain.java:84) 
at test.TestMain.run(TestMain.java:43)  at test.TestMain.main(TestMain.java:27)

<<attachment: test.cl.gif>>

Reply via email to