tomee-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "John D. Ament" <john.d.am...@gmail.com>
Subject Re: TransactionAttribute
Date Fri, 06 Sep 2013 00:14:29 GMT
>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??

Mime
View raw message