This one time, at band camp, Jacek Kruszelnicki said:

JK >I cannot update object Test t, since it is entirely new - does not exist in
JK >the DB or in cache yet.
JK >So I call the constructor
JK >
JK >Test t= new Test(70);
JK >
JK >then I fetch an existing (in the DB) object of type Company
JK >
JK >Company c = pm.findByPrimaryKey(test.Company.class, new Integer(30));
JK >
JK >then set object t to point to object c
JK >
JK >t.setCompany(c);
JK >
JK >and finally, I want to create t in the persistent sense:
JK >
JK >pm.create(t)
JK >
JK >I cannot call pm.update(t) since t does not exist in the DB yet.
JK >
JK >>Take a look at org.exolab.castor.jdo.Database.update(). Also why
JK >>are you using a pm.create()? I believe that this is part of the
JK >>problem. If I'm not mistaken, this forces a create. commit() might
JK >>have been a better choice here.

Jacek,

Yes, you're correct that you cannot update() Test t whose id is
70. You're attempting to relate Company c to Test t using setCompany(c)
but Castor has no idea who Company c is yet. First you need to
fetch Company c (and you already do that) and then you need to call
pm.update( c ) to make Castor aware of it. Then I would recommend
a pm.commit( t ) instead of a pm.create( t ).

example:

    Test t = new Test( 70 );
    Company c - pm.findByPrimaryKey( test.Company.class, new Integer( 30 ) );
    pm.update( c );
    t.setCompany( c );
    pm.commit( t );

--

perl -e 'print unpack("u30","<0G)U8V4\@4VYY9&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

Reply via email to