You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cactus-user@jakarta.apache.org by Stefan Groschupf <sg...@media-style.com> on 2004/08/18 18:36:31 UTC
outside the scope of a transaction
Hi,
I use cactus to test my ejbs in weblogic 8.1 sp2.
There something i could not find any starting point to track down the
problem.
I have in my test case a line:
assertEquals(0,
KitUtil.getLocalHome().findByPrimaryKey(kitLocal.getUniqueSequence()).ge
tSubscribers().size());
At least I just test a entity n:n entity bean relation in this line.
I got this exception:
[junit] Caused an ERROR
[junit] [EJB:010116]Attempted to access the collection valued
cmr-field, 'subscribers', for bean, 'Kit', outside the scope of a
transaction. All access to the collection must be performed during the
transaction in which the collection was initially retrieved.
[junit] java.lang.IllegalStateException: [EJB:010116]Attempted to
access the collection valued cmr-field, 'subscribers', for bean, 'Kit',
outside the scope of a transaction. All access to the collection must
be performed during the transaction in which the collection was
initially retrieved.
I was asking already the bea support guys but they suggest do not use
this kind of strange tools since .... ;-o
They say the the cactus servlet will not run inside a transaction and
my findbyprimary key run every-time in a transaction.
Thats way there will be no solution for this problem. ;(
I do not comment this answer. ;-(
Anyway it is difficult for me to test my ejbs in case I can not use the
getter methods that returns collections of other enitity beans.
So far was able to workaround by testing the content of my DTO that was
generated by a DTOFactory session bean, where I have no problems at
all.
Someone has any idea what I can do to test getter methods collections
of entity bean i was finding by primary key?
Thanks for any hints.
Stefan
Re: ... a transaction, reset caller principal
Posted by Stefan Groschupf <sg...@media-style.com>.
Hi Kazuhito,
thank you that helped very much!
I notice a strange side effect.
After closing the transaction my caller principal is reseted.
So I use the authentication mechanism described in cactus doc and it
working fine in my test method until i start / commit the transaction.
Someone have any idea what kind of relation transactions and the caller
principal have in weblogic?
Thanks
Stefan
Am 19.08.2004 um 03:32 schrieb Kazuhito SUGURI:
> Hi Stefan,
>
> In article <C2...@media-style.com>,
> Wed, 18 Aug 2004 18:36:31 +0200,
> Stefan Groschupf <sg...@media-style.com> wrote:
> sg> [junit] Caused an ERROR
> sg> [junit] [EJB:010116]Attempted to access the collection valued
> sg> cmr-field, 'subscribers', for bean, 'Kit', outside the scope of a
> sg> transaction. All access to the collection must be performed during
> the
> sg> transaction in which the collection was initially retrieved.
>
> As the error message says, you need to begin transaction
> to access to the collection (retrived for n:n relation).
>
> For example, I have used codes for CMR test with JBoss like follows:
> public class CmrTestCase
> extends ServletTestCase
> {
> protected UserTransaction transaction = null;
> protected beginTransaction(){
> if(transaction==null){
> transaction =
> (UserTransaction)context.lookup("java:comp/env/UserTransaction");
> }
> transaction.begin();
> }
> protected commitTransaction(){
> if(transaction==null){
> return;
> }
> if(transaction.getStatus()==Status.STATUS_ACTIVE){
> transaction.commit();
> }
> }
>
> public void testXXX(){
> beginTransaction();
> // test codes for CMR etc.
> commitTransaction();
> }
> }
>
>
> Hope this helps.
> ----
> Kazuhito SUGURI
> mailto:suguri.kazuhito@lab.ntt.co.jp
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: cactus-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: cactus-user-help@jakarta.apache.org
>
>
Re: outside the scope of a transaction
Posted by Kazuhito SUGURI <su...@lab.ntt.co.jp>.
Hi Stefan,
In article <C2...@media-style.com>,
Wed, 18 Aug 2004 18:36:31 +0200,
Stefan Groschupf <sg...@media-style.com> wrote:
sg> [junit] Caused an ERROR
sg> [junit] [EJB:010116]Attempted to access the collection valued
sg> cmr-field, 'subscribers', for bean, 'Kit', outside the scope of a
sg> transaction. All access to the collection must be performed during the
sg> transaction in which the collection was initially retrieved.
As the error message says, you need to begin transaction
to access to the collection (retrived for n:n relation).
For example, I have used codes for CMR test with JBoss like follows:
public class CmrTestCase
extends ServletTestCase
{
protected UserTransaction transaction = null;
protected beginTransaction(){
if(transaction==null){
transaction = (UserTransaction)context.lookup("java:comp/env/UserTransaction");
}
transaction.begin();
}
protected commitTransaction(){
if(transaction==null){
return;
}
if(transaction.getStatus()==Status.STATUS_ACTIVE){
transaction.commit();
}
}
public void testXXX(){
beginTransaction();
// test codes for CMR etc.
commitTransaction();
}
}
Hope this helps.
----
Kazuhito SUGURI
mailto:suguri.kazuhito@lab.ntt.co.jp