Bruce, 

Partial success on this issue ...

A co-worker was able to make it run off a fresh build of the latest castor code 
0.9.4.3   -  no longer throws the exception ... HOWEVER... if after the line:  

product = (Product) results.next();

//I insert the following the lines:

System.out.println("its a:" +  product.getClass() );
System.out.println("is a Product?" + (product instanceof Product));
System.out.println("is a Computer?" + (product instanceof Computer));

Then I get:

its a:class myapp.Product
is a Product? true
is a Computer? false

Please correct me if Im wrong but if the Product happens to be a Computer then 
instanceof should tell us that shouldn it?

Thanks - Rich


-----Original Message-----
From: Bruce Snyder [mailto:[EMAIL PROTECTED]
Sent: Thursday, March 27, 2003 6:25 AM
To: [EMAIL PROTECTED]
Subject: Re: [castor-dev] JDO inheritance problem


This one time, at band camp, Schramm, Rich said:

SR>It might be easier demo the problem Im having by using the jdo examples.  It seems 
to me a reasonable thing to want to do is update the price of all products in the 
database... however in the examples, Computer extends Product.  Test.java creates a 
computer instance with Id = 11, there are also generic products created, eg one with 
Id = 4.  If you add the following bits of code at the bottom of test.java... updating 
the price of the selected product... it fails in the last case.... where "Product" 
happens to also be a "Computer"
SR>I get:    IllegalArgumentException: object is not an instance of declaring class
SR>
SR>I cant seem to grock a casting strategy that works correctly for Products if they 
happen to be Computers..
SR>(Note..There is a jdoLoad method in Product.java that tests the name field for 'PC' 
and returns a Class.Computer but that doesnt seem to change the outcome (I tried 
changing name 'myPC' to 'foobar').)
SR>
SR>I think if I can get past this simple example it might just get me past my more 
complicated real-life problem (wishfull thinking...)  Thanks again for any suggestions!

Rich,

I think that this may be an issue with Castor not walking the
inheritance tree. I changed to the code to also try the following
and I receive a slightly different exception:

    /**** price update FAILS for Product id = 11 (a computer) ***/
    db.begin();
    productOql.bind( 11 );
    results = productOql.execute();
    if ( !results.hasMore() ) { writer.println("Query failed"); } else
    {
        // product = (Product)results.next();
        computer = ( Computer ) results.next();
        // writer.println("Found Product: "  + product.toString() );
        writer.println("Found Computer: "  + computer.toString() );
        // product.setPrice(999);
        computer.setPrice(999);
    }
    db.commit();

I'll file a Bugzilla report on this issue and attach your code
additions to the JDO examples.

Bruce
--

perl -e 'print unpack("u30","<0G)[EMAIL PROTECTED]&5R\"F9E<G)E=\$\!F<FEI+F-O;0\`\`");'

----------------------------------------------------------- 
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
        unsubscribe castor-dev

----------------------------------------------------------- 
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
        unsubscribe castor-dev

Reply via email to