On Oct 27, 2005, at 05:53, Armin Waibel wrote:
Hi Jason,
> 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.
I think this is the intended behavior. You add the same foo object
twice in bar - why and how should OJB differ? You expect 2 entries
in indirection table for the same bar/foo combination?
How did OJB notice the autoincrement 'id' column in foo_bar?
Armin,
I expect two entries in indirection table for the same bar/foo
combination _at different indices_ of the collection being preserved.
When I turn SQL generation debugging on via log4j like this:
log4j.logger.org.apache.ojb.broker.accesslayer.sql.SqlGeneratorDefaultIm
pl=DEBUG
I get output like the following:
DEBUG [TP-Processor7] (?:?) - SQL:INSERT INTO bar (name) VALUES (?)
DEBUG [TP-Processor7] (?:?) - SQL:INSERT INTO foo (name) VALUES (?)
DEBUG [TP-Processor7] (?:?) - SQL:INSERT INTO foo_bar (bar_id,foo_id)
VALUES (?,?)
DEBUG [TP-Processor7] (?:?) - SQL:INSERT INTO foo_bar (bar_id,foo_id)
VALUES (?,?)
versus the PSpy output for the very same execution:
1130385321625|33|0|statement||select count(*) from foo
1130385321712|2|0|statement||INSERT INTO bar (name) VALUES ('bar1')
1130385321729|4|0|statement||SELECT LAST_INSERT_ID() FROM bar LIMIT 1
1130385321768|2|0|statement||INSERT INTO foo (name) VALUES ('foo1')
1130385321770|2|0|statement||SELECT LAST_INSERT_ID() FROM foo LIMIT 1
1130385321774|2|0|statement||INSERT INTO foo (name) VALUES ('foo2')
1130385321776|2|0|statement||SELECT LAST_INSERT_ID() FROM foo LIMIT 1
1130385321808|2|0|statement||INSERT INTO foo_bar (bar_id,foo_id)
VALUES ('14','17')
1130385321836|1|0|commit||
So it seems to me that OJB is suppressing an insertion into the
indirection table. My educated guess was that perhaps within the
transaction it was checking to see if it had already inserted a value
in the indirection table for that bar/foo combination, and not
performing the insertion the 2nd - Nth times it encounters that pairing.
- Jason
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]