Skip to Content
0
Former Member
Jan 15, 2007 at 06:38 PM

CMP EJB: Bean Transaction type problem

26 Views

I wanted to open several transaction and some non-transactional queries into a Session Bean's method, so I used Bean Transaction type for the Session Bean.

But after closing the first transaction, I got this exception when I try to get a collection from two relationed beans.

java.lang.IllegalStateException: com.sap.engine.services.ejb.exceptions.BaseIllegalStateException: The collection is obtained by another transaction.

at com.sap.engine.services.ejb.entity.pm.multiple.ReferenceCollection.checkLocker(ReferenceCollection.java:351)

at com.sap.engine.services.ejb.entity.pm.multiple.ReferenceCollection.iterator(ReferenceCollection.java:442)

...

The code is something like this:

Bean2 has a relationship (1-n) with Bean3, called items (for example).

public void method() {

Bean1 bean1 = createBean1();

Bean2 bean2 = bean2Home.findByPrimaryKey(bean1.getBean2Id());

Collection c = bean2.getItems();

Iterator it = c.iterator(); <============= I get the exception here !!!

...

}

private Bean1 createBean1() {

Bean1 bean1 = null;

UserTransaction ut = myContext.getUserTransaction();

try {

ut.begin();

...

bean1 = bean1Home.create();

ut.commit();

} catch (Exception e) { ut.rollback(); }

return bean1;

}

There is no relationship at EJB level between Bean1 and Bean2. Bean1 has a foreign key to Bean2 but only at database level.

I'm using WAS 7.0 SP 6 (NW04sSR1).

I use a datasource defined in WAS with oracle driver 10.1.0.2, native SQL type and default connection isolation set to DEFAULT. I tried with TRANSACTION_NONE too with no success.

There is no special isolation level defined in ejb-j2ee-engine.xml (I suposse it takes default Read-Committed for everything).

There is only one thread which I'm using to test it.

I've seen the SQL Trace from OpenSQLMonitors and I don't see where is the lock.

Help needed. Thanks in advance.