Hi,
 I posted yesterday and last week about a problem I was having with CMR when
I upgraded from 3.2.0 to 3.2.2. I've done more investigation and I don't
think my previous mails were entirely accurate (or very clear) so let me
start over. 

 The Problem:
 I'm experiencing NPE in our app because the CMR relationships are
(apparently) not being created. This didn't occur with our app in 3.2.0. 

 I have a sample case which I believe is representitive of the problem I'm
seeing in our app. The beans are Foo & Bar (sorry about the naming). The
relationship is N-Foo-1-Bar. The relation is being set in post create:

public abstract class FooEJB extends AbstractEntityBean {
...
    public void ejbPostCreate(BarLocal bar, String fooValue) throws
CreateException {
        sLog.debug("ejbPostCreate(" + getId() + ")");
        
        this.setBar(bar);
    }
...
}
 
And I have a test session which does the following:

...
            BarLocal bar = createBar("This is a bar");
            FooLocal foo = createFoo(bar, "This is a foo");
            
            sLog.info("****************************************");
            sLog.info("Bar id through foo: " + foo.getBar().getId());
            sLog.info("Bar id through bars foos: ");

            Collection foos = bar.getFoos();            
            sLog.info("Number of foos associated with bar: " + foos.size());

            Iterator fooIter = bar.getFoos().iterator();
            while (fooIter.hasNext()) {
                FooLocal tmpFoo = (FooLocal) fooIter.next();
                sLog.info("Foo id: " + tmpFoo.getId());
                sLog.info("Bar id: " + tmpFoo.getBar().getId());
            }
            sLog.info("****************************************");
...

I'd expect the output of this test case to be:

18:58:38,875 INFO  [FooBarSessionEJB]
****************************************
18:58:38,890 INFO  [FooBarSessionEJB] Bar id through foo: 1011
18:58:38,890 INFO  [FooBarSessionEJB] Bar id through bars foos: 
18:58:38,890 INFO  [FooBarSessionEJB] Number of foos associated with bar: 1
18:58:38,906 INFO  [FooBarSessionEJB] Foo id: 1017
18:58:38,906 INFO  [FooBarSessionEJB] Bar id: 1011
18:58:38,906 INFO  [FooBarSessionEJB]
****************************************

What I'm actually seeing is:

18:58:38,875 INFO  [FooBarSessionEJB]
****************************************
18:58:38,890 INFO  [FooBarSessionEJB] Bar id through foo: 1011
18:58:38,890 INFO  [FooBarSessionEJB] Bar id through bars foos: 
18:58:38,890 INFO  [FooBarSessionEJB] Number of foos associated with bar: 0
18:58:38,906 INFO  [FooBarSessionEJB]
*******************************************

If I add a finder call after the beans are created (which forces the beans
to be synchronized to the database) then I get the results I expect. This
makes me think that there's a problem with the  caching - the "bar" returned
by the create() call is not the same Bar instance as returned by
foo.getBar(). Which means that I have 2 instances of the same bean within
the same transaction which have different state - seems like a bug to me,
I'd have expected the foo.getBar() call to return the same "bar" as was
passed to the create() call.

I've attached the source. For the sample, let me know what you think,

thanks,
gavin

Attachment: FooEJB.java
Description: Binary data

Attachment: FooBarSessionEJB.java
Description: Binary data

Attachment: BarEJB.java
Description: Binary data

Attachment: testSchema.sql
Description: Binary data

Reply via email to