cancel
Showing results for 
Search instead for 
Did you mean: 

CMP EJB: Bean Transaction type problem

Former Member
0 Kudos

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.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

probably it's too late to answer, but better late than never

they use lazy loading or something for the collections, so the getter should be called in the same tx context as the bean is retrieved. Why not to have the method() with "Required" tx attribute and not to handle transactions by yourself?

Former Member
0 Kudos

Thanks. I finally used Required attribute.

But anyway I did never figure out what was happening.

As you can see, the retrieve of bean2, and the collection are outside any tx contect.

The transaction is to create another (supossely) unrelated bean.

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi All,

I too gets the same exception.

<b>com.sap.engine.services.ejb.exceptions.BaseIllegalStateException: The collection is obtained by another transaction.</b>

Did anyone resolved this issue?. Please let me know how you have resolved this.

Thanks,

Sekar

Former Member
0 Kudos

Hi Sekar

have you solved your problem? I am facing the same exception, have no idea what is wrong, looks like the collection returned from the relationship can not be touched coz it's used by another transaction, however no clue why this happens.

My code is very standard like:

TimeStatusEntityLocal ts = tsHome.findByPrimaryKey(pk);

Collection distribution = ts.getDistributionByStatus();

Iterator it = distribution.iterator();

Exception occurs when iterates the collection.

Hi, Anibal, seems like you solved the problem, but I don't understand what "I finally used Required attribute" means, can you please give me some hints? or please answer in my question ", so that I can award you.

Thank you, guys.

Jayson