On 10/27/05, Jason A. Lunn <[EMAIL PROTECTED]> wrote:
>      I have an indirection table foo_bar that happily implements an
> m:n relationship between foo and bar. the columns of foo_bar include
> foo_id, bar_id, and a unique id for the association itself (mysql
> backend, the id column is inserted automatically). This is because it
> is relevant to my application to materialize references to the same
> object at different indices of the collection upon retrieval.
>
> I started out doing all the insertion into this table by hand. When I
> retrieve foo or bar, I successfully get a collection containing all
> the expected elements at all the right indices. But now I'm trying to
> get more sophisticated, and thus writing an online editor for this
> relationship instead of populating the foo_bar table through the
> mysql command line. What I'm finding is that OJB is deduping my
> collection by ignoring successive references to elements it has
> already seen in the current transaction. The result is that I don't
> get as many rows inserted into my indirection table as I want.
>
> For instance:
>
>          Foo foo1 = new Foo();
>          Bar bar1 = new Bar();
>
>          broker.beginTransaction();
>          broker.store( bar1 );
>          broker.store( foo1 );
>
>          bar1.getFoos().add( foo1 );
>          bar1.getFoos().add( foo1 );
>
>          broker.store( bar1 );
>          broker.commitTransaction();
>
> I would expect the above to result in an insert into the foo table,
> an insert into the bar table, and 2 insertions into the foo_bar
> table. I get the expected behavior in the foo and bar tables, but I
> only get one new record into the foo_bar table.
>
> Someone I know suggested that I manually iterate over the collection
> using the link() and unlink() methods of BrokerHelper, but I was
> convinced that there was a more elegant way to do this, possibly a
> configuration file tweak to tell OJB to create multiple links in the
> indirection table rather than assuming that I only want one.
>
> Your thoughts appreciated.

How is the indirection table defined in the database ? Is there a
compound primary key defined over the columns used to refer to the two
classes ?
Also, you could configure P6Spy to trace the generated SQL in order to
see whether OJB or the database ignores the second insert. Details on
how to configure P6Spy can be found here:

http://db.apache.org/ojb/docu/faq.html#traceProfileSQL

Tom

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

Reply via email to