You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by Ravindranath Akila <ra...@gmail.com> on 2010/03/23 09:30:21 UTC

Re: REQUIRES_NEW within a NEVER transaction throwing an exception, bug or misuse?

Finalizing on this thread:
As I have mentioned before, I used an alternative method as I was getting
exceptions. However, a new requirement came up and I had to use a *REQUIRES_NEW
*method within a *NOT_SUPPORTED *method and the code worked without fail.
Either I did something mysteriously wrong before or the *issue got fixed
along the path of OpenEJB*. I am using the latest. Nevertheless, I will
paste the now working methods here. Please note that "All these beans are in
*STATELESS*".

Just for your evaluation, as now the cause of this thread is lost.

*Parent method:*

    @Override
    @TransactionAttribute(TransactionAttributeType.*NOT_SUPPORTED*)
    public Return<HumansPrivateLocation> doDirtyRHumansPrivateLocation(final
RefObj<String> humanId) {
        Return<HumansPrivateLocation> r;
        try {
            r = new
ReturnImpl<HumansPrivateLocation>(rHumansPrivateLocation_.doNTxRHumansPrivateLocation(humanId.getObj()),
READ_HUMANS_PRIVATE_LOCATION_SUCCESSFUL);
        } catch (final Throwable t) {
            r = new ReturnImpl<HumansPrivateLocation>(t,
READ_HUMANS_PRIVATE_LOCATION_FAILED, true);
        }
        return r;
    }

*Which calls:*

    @Override
    @TransactionAttribute(TransactionAttributeType.*REQUIRES_NEW*)
    public HumansPrivateLocation doNTxRHumansPrivateLocation(String humanId)
{
        final HumansPrivateLocation hpl =
humansPrivateLocationCrudServiceLocal_.findBadly(HumansPrivateLocation.class,
humanId);
        hpl.getPrivateLocationsOwned().size();//Initializing list
        hpl.getPrivateLocationsViewed().size();//initializing list
        return hpl;
    }

*Which calls:*

    @Override
    @TransactionAttribute(TransactionAttributeType.*SUPPORTS*)
    public T findBadly(Class typeOfEntity, Object idByWhichToLookup) {
        final Object object = entityManager.find(typeOfEntity,
idByWhichToLookup);
        if (object != null) {
            return (T) object;
        } else {
            throw ENTITY_NOT_FOUND_EXCEPTION;
        }
    }

On Mon, Nov 16, 2009 at 11:04 AM, Ravindranath Akila <
ravindranathakila@gmail.com> wrote:

> I have an operation on which
>
> one is a dirty read, so the transaction scope is NEVER
> and the other requires a transaction, hence REQUIRES_NEW.
>
> I need to call both these in the same bean so unless I mark this caller
> method otherwise, it defaults.
> Therefore I tried marking it NEVER, NOT_SUPPORTED and SUPPORTS but all
> these throw exceptions.
>
> Caller Method = A
>
> A => NEVER or NOT_SUPPORTED or SUPPORTS
>
> Called Methods = B and C
>
> B => NEVER, NOT_SUPPORTED (this is the dirty read)
> C => REQUIRES_NEW
>
> A calls B, then C
>
> it seems that using ANY transaction scope, i.e. all enlisted in
> transactionattribute class I cannot call both the two other methods, one not
> supporting or rejecting a transaction(B) and the other requiring a new
> one(C).
>
> I agree that nested transactions are not supported in EJB, but if the
> caller(A) is marked NEVER, NOT_SUPPORTED or SUPPORTS, and was called from an
> ordinary method(having no transaction scope), then it should not impose any
> transaction to methods IT calls. It if it does, it should sleep and let them
> handle it from there. I could not find anything on Google or the Sun
> tutorial.
>
> Please help me with this.
>



-- 
Thanks a lot for the help,
 Cheers!
  Akila...