I am not sure I understand what you want to know,
but I think you mean: how to create or remove a n:m relationship
between two objects. I have some questions about that also,
maybe one of the guru's could shed some light on this.
Our application is using these MtoN relations with success,
and I am very pleased with most of the things in OJB.
[But we only use the PB API, no experience with ODMG or JDO, and
version 0.9.5 (preparing the move to 0.9.9)]
For example we have such a bidirectional relationship between
user objects and group objects, where a user can be in many groups
(and groups can have many users).
The relationship is mapped on a table that you create, with two columns
f.i. columns id_user and id_group. But you do not directly access this table,
instead you have two collections, f.i. user.groups and group.users, as
defined in de repository.xml mapping table.
To create a relation you insert a user instance in the group.users collection,
with normal Java code. And then you persist the group. This is done via
persistence broker store. This will cause the collection to be scanned,
and the relationship table will be filled. And before it is filled,
the existing relations are deleted (to make room for the (re)creation of the
relations :->)
No the problem with this is, as far as I can see, that you do not really
have CRUD on the relationbship table. It all goes automagically.
So if the collection is big, then all its relations will be dropped,
and then rebuilt, which is not always the most efficient thing to do.
And the OJB cache also has to be taken care of (this may have been
improved in versions after 0.9.5). That is, the user.groups collection
will not automatically be updated, so you have to make sure that you
do not store that instance without updating its collection, or else
you will undo the new relationships and restore the old. The way we
solve this is by updating both the objects (using an application method
called "link (obj_a, obj_b, collection_field_name_a, collection_field_name_b)"
[the collections are both updated, and both objects are stored]
and also removing the cached instances from the OJB cache.
However, this does seem to be quite an inefficient operation. I am sure we are
doing something wrong here, or at least doing something suboptimal.
So as far as I know, these "automagic" MtoN collections are great
for retrieval (the certainly are nice in combination with collection proxies),
but can be a pain to maintain. I would really like to hear others about
their experiences.
Regards,
Theo
> Van: Jeffrey Gilbert [mailto:[EMAIL PROTECTED]
> Verzonden: donderdag 27 februari 2003 22:41
> Aan: [EMAIL PROTECTED]
> Onderwerp: How does one CRUD a M:N relationship. Any solid examples of
> CRUD! CRUD! CRUD! CRUD!
>
>
> Hi,
>
> I've setup a non-decomposed M:N relationship in my datastore so now how do I
> CRUD (create, read, update and delete) records that participate in this
> relationship? An example provided by the OJB website for adding records to
> datastore does exist but doesn't reflect any type of advanced relationship
> between tables. How would one modify this example to reflect a M:N
> relationship? What I'm really looking for CRUD!!! I want CRUD! Yummy CRUD!
> Okay, I'm being silly... Any help would be appreciated.
>
> *** Simple example CUT FROM PersistenceBroker API documentation ***
> public void apply()
> {
> // this will be our new object
> Product newProduct = new Product();
> // now read in all relevant information and fill the new object:
> System.out.println("please enter a new product");
> String in = readLineWithMessage("enter name:");
> newProduct.setName(in);
> in = readLineWithMessage("enter price:");
> newProduct.setPrice(Double.parseDouble(in));
> in = readLineWithMessage("enter available stock:");
> newProduct.setStock(Integer.parseInt(in));
>
> // now perform persistence operations
> try
> {
> // 1. open transaction
> broker.beginTransaction();
>
> // 2. make the new object persistent
> broker.store(newProduct);
> broker.commitTransaction();
> }
> catch (PersistenceBrokerException ex)
> {
> // if something went wrong: rollback
> broker.abortTransaction();
> System.out.println(ex.getMessage());
> ex.printStackTrace();
> }
> }
>
>
> Thanks in advance,
>
> Jeff
>
> ---------------------------------------------------------------------
> 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]