I have a problem where key-generation does not seem to be happening in
the proper order when updating classes with multiple levels of
dependency. I am using a HIGH/LOW keygenerator with a MySQL database.

I've supplied a test case including a full set of classes, mapping file, sql 
tables etc in a jar attached to this message. 

Here's a description of the problem:

It seems that newly created classes are not assigned keys prior to the
update/creation of their parent classes in the database when the parent class
itself a class dependent on a higher level (non-dependent) class. In my
case, since I'm using integers as keys, a 0 is showing up in the row
corresponding to the parent class, but the key is properly assigned to
the child class.

I've tried to distill the problem into the simplest test case that's capable
of illustrating the issue, here's what I have come up with:

I have 3 classes, A, B, C. C depends on B, B depends on A.

Each class has a 1-1 relationship with those that it depends on, and
bi-directional references are maintained so that each B has a
reference to C each C has a reference to B, each A has a reference to
B and each B has a reference to A.

I use 2 transactions. In the first, I create a single instance of 
c, b, a using the following code:

    A a = new A(); B b  = new B(); C c = new C();

    b.setChild(c);  c.setParent(b);
    b.setParent(a); a.setChild(b);
                
    db.begin();
    db.create(a);                
    db.commit();

>From within a second transaction, I use an OQL query to lookup 'A's in
the database:

    oql = db.getOQLQuery("SELECT a From A a ");
    A result = null;

    db.begin();
    results = oql.execute();
    while (results.hasMore()) {
        result = (A) results.next();
    }

>From within the same transaction, I create a new B and C and
assign them to the A returned by the query.

     C c = new C(); B b = new B();
                
     c.setParent(b); b.setChild(c);
     b.setParent(result); result.setChild(b);

     db.commit();

This successfully creates the new B and C objects in the database, and
deletes the old B and C originally created in the first
transaction. The only problem is that the row in the database
corresponding to the newly created B object has a child_id of '0',
which isn't the id of the newly created C object. The row
corresponding to the newly created C object has a properly assigned
key.

Has anyone seen anything like this? I'd really like to use dependency here 
although I guess I could do a workaround using the Persistent
interface or and not relying on class dependency to do my work for me.

If anyone has any idea of where I might poke around to fix this, I wouldn't 
mind giving it a shot. It seems like it could be something as simple as 
depth-first traversal of a class dependency tree.

Thanks for your time,

Drew Farris

--
Drew Farris <[EMAIL PROTECTED]>
Systems Engineer 
MNIS-TextWise Labs

Attachment: testcase3.jar
Description: Zip archive

Reply via email to