tomee-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From José Luis Cetina <maxtorz...@gmail.com>
Subject Re: TransactionAttribute
Date Fri, 06 Sep 2013 17:39:32 GMT
I fixed using @TransactionAttribute(TransactionAttributeType.REQUIRED) in
the class (the default) and then an each method if i dont need a
transaction i use @TransactionAttribute(TransactionAttributeType.NEVER)





2013/9/6 José Luis Cetina <maxtorzito@gmail.com>

> Hi, i have a problem with this.
>
> My EJB is annotated with TransactionAttributeType.NEVER and
> TransactionManagementType.CONTAINER, my ejb method use
> TransactionAttributeType.REQUIRED, my idea is that every method when need a
> transaction they use TransactionAttributeType.REQUIRED and then persist,
> but im getting a TransactionRequiredException. If my method says required
> why i got that exception?
>
> Example:
>
> @Stateless
> @TransactionAttribute(TransactionAttributeType.NEVER)
> @TransactionManagement(TransactionManagementType.CONTAINER)
> public class MyEJB{
>
> @TransactionAttribute(TransactionAttributeType.REQUIRED)
> public void myMethod(MyClass obj){
>    entityManager.persist(obj);
>   }
> }
>
>
> Log:
> SEVERE - EjbTransactionUtil.handleSystemException: null
> javax.persistence.TransactionRequiredException
> at
> org.apache.openejb.persistence.JtaEntityManager.assertTransactionActive(JtaEntityManager.java:105)
>  at
> org.apache.openejb.persistence.JtaEntityManager.persist(JtaEntityManager.java:134)
>
>
>
> 2013/9/5 José Luis Cetina <maxtorzito@gmail.com>
>
>> Ok, understood. Thanks
>>
>>
>> 2013/9/5 John D. Ament <john.d.ament@gmail.com>
>>
>> From the java ee 5 tutorial (don't think this changed in 6):
>>> http://docs.oracle.com/javaee/5/tutorial/doc/bncij.html
>>>
>>> Required Attribute
>>>
>>> If the client is running within a transaction and invokes the
>>> enterprise bean’s method, the method executes within the client’s
>>> transaction. If the client is not associated with a transaction, the
>>> container starts a new transaction before running the method.
>>>
>>> The Required attribute is the implicit transaction attribute for all
>>> enterprise bean methods running with container-managed transaction
>>> demarcation. You typically do not set the Required attribute unless
>>> you need to override another transaction attribute. Because
>>> transaction attributes are declarative, you can easily change them
>>> later.
>>>
>>> John
>>>
>>> On Thu, Sep 5, 2013 at 8:09 PM, José Luis Cetina <maxtorzito@gmail.com>
>>> wrote:
>>> > Hi i have an EJB annotated with:
>>> >
>>> > @Stateless
>>> > @TransactionManagement(TransactionManagementType.CONTAINER)
>>> >
>>> > As you can see i don't mark the EJB with any TransactionAttribute,
>>> instead
>>> > i use
>>> > TransactionAttribute in every method when i need it, if i don't need
>>> any
>>> > transaction (because i will only read information from database) then i
>>> > don't use any TransactionAttribute in the method not event
>>> > TransactionAttribute.NEVER.
>>> >
>>> > But today i realized that i have a method that IS NOT annotated with
>>> > any TransactionAttribute (and the ejb class either) but in that method
>>> i
>>> > query an entity and change some values  (inside of the ejb method) of
>>> the
>>> > retrieved entity, i could see that my entity is committed with those
>>> > changes (this is not suppose to happens).
>>> >
>>> > I know if i mark the EJB with TransactionAttribute.XXX all the methods
>>> will
>>> > use the same TransactionAttribute that is defined in the class, i know
>>> if i
>>> > have the TransactionAttribute in the ejb class and in the method too,
>>> the
>>> > method TransactionAttribute has major priority. But in my case
>>> > i don't have any TransactionAttribute in the ejb class and in the
>>> method.
>>> >
>>> > Then why my entity is commited with those changes?, is the default
>>> value
>>> > for TransactionAttribute using TransactionManagementType.CONTAINER
>>> > is @TransactionAttribute(TransactionAttributeType.REQUIRED) or
>>> something
>>> > like that??
>>> >
>>> > If i annotated my method
>>> > with @TransactionAttribute(TransactionAttributeType.NEVER) the entity
>>> is
>>> > never persisted (required behavior), but if i add
>>> > the @TransactionAttribute(TransactionAttributeType.REQUIRED) then the
>>> > entity is persisted.
>>> >
>>> > My surprise is if i use
>>> > @TransactionAttribute(TransactionAttributeType.REQUIRED) the entity is
>>> > persisted but i never do a persist or merge, i know if the method never
>>> > throw an exception the transaction is commited, but i never do a
>>> > persist/merge.
>>> >
>>> > Do i have to mark all of my methods with
>>> > @TransactionAttribute(TransactionAttributeType.NEVER)?? if yes, then i
>>> can
>>> > assume that the default value for an EJB is
>>> @TransactionAttribute.REQUIRED??
>>>
>>
>>
>>
>> --
>> -------------------------------------------------------------------
>> *SCJA. José Luis Cetina*
>> -------------------------------------------------------------------
>>
>
>
>
> --
> -------------------------------------------------------------------
> *SCJA. José Luis Cetina*
> -------------------------------------------------------------------
>



-- 
-------------------------------------------------------------------
*SCJA. José Luis Cetina*
-------------------------------------------------------------------

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message