Hi Brad,

Bradford Pielech wrote:

Hello:

This is a follow on to my question from last week where I have a graph structure where each graph node has a list of parents and children. I was trying to use the auto-update=object and auto-delete=object features, but it was not working well in my particular scenario (meaning there were not any bugs in OJB) so I am investigating switching to auto-update and auto-delete = none and linking / unlinking on my own.

So here is my question: if I have object A and object B already stored in the database, how can I create or delete an M to N link between them in their indirection table? I know that the BrokerHelper link and unlink methods are the way to go, but I cannot see how to use it because, to me, it looks like you can only specify 1 side of the link.

If you specify one side of the link this should be enough, because in indirection table the FK of both objects are inserted - or I'm missing something?
For example:
A, B already existing.
// declare relation
A.addBs(B)
broker.beginTx
broker.serviceBrokerHelper().link(A);
broker.commitTx


After this in indirection table the m:n relation between A and B should be stored.

If you now call
broker.retrieveAllReferences(B)
Collection result = B.getAs()
B now should contain A

There is a test case in test suite ([db-ojb/src/test]) called org.apache.ojb.broker.M2NTest handle with m:n relation (automatic store and custom store with linking)

regards,
Armin


Here is some rough sample code of what I want to do:
-----------
PersistenceBroker pbroker = PersistenceBrokerFactory.defaultPersistenceBroker();
pbroker.beginTransaction();
pbroker.store(a);
pbroker.commitTransaction();


    //then some time later
    pbroker.beginTransaction();
    pbroker.store(a);
    pbroker.commitTransaction();

//and finally even later
pbroker.serviceBrokerHelper().link(a,b); //I know this method doesn't exist, but this is what I want to do.
// or
pbroker.serviceBrokerHelper().unlink(a,b);
-------------


Here is what the repository file for the DAGNode looks like:

<collection-descriptor
        name="children"
        element-class-ref="DAGNode"
        indirection-table="parent_children_table"
        auto-retrieve="true"
        auto-update="none"
        auto-delete="none"
    >
        <fk-pointing-to-this-class column="parent_id"/>
        <fk-pointing-to-element-class column="child_id"/>
    </collection-descriptor>
    <collection-descriptor
        name="parents"
        element-class-ref="DAGNode"
        indirection-table="parent_children_table"
        auto-retrieve="true"
        auto-update="none"
        auto-delete="none"
    >
        <fk-pointing-to-this-class column="child_id"/>
        <fk-pointing-to-element-class column="parent_id"/>


thank you! Brad






--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]




--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to