on 01-15-2007 6:38 PM
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.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
User | Count |
---|---|
90 | |
10 | |
10 | |
10 | |
7 | |
7 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.